0
java -jar ngdbc.jar -c "SELECT Name as Title, Desc as Description FROM `table_name` "

I want to add an argument with back-ticks within the query string. However when I execute it in the terminal the back-ticks get executed first and it says zsh: command not found: table_name. Any ideas on how to work around the problem ?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • Work around: Don't use backticks inside double quotes, or escape them. They are supposed to be expanded. What's the purpose of having literal backticks in a SQL statement anyway? – user1934428 Aug 12 '21 at 11:26
  • 1
    @user1934428 That's the required syntax for some dialects of SQL. – chepner Aug 12 '21 at 17:02

2 Answers2

0

Backticks are subject to expansion in a double-quoted string. Either escape the backticks individually

java -jar ngdbc.jar \
   -c "SELECT Name as Title, Desc as Description FROM \`table_name\`"

or use single quotes for the entire argument

java -jar ngdbc.jar \
   -c 'SELECT Name as Title, Desc as Description FROM `table_name`'

In shell, backticks are an old form of command substitution. For example,

$ echo "Command substitution: `echo 3`"
Command substitution: 3

This is equivalent to the newer, nestable, more readable form $(...):

$ echo "Command substitution: $(echo 3)"
Command substitution: 3a
chepner
  • 497,756
  • 71
  • 530
  • 681
-1

try to use this one

java -jar ngdbc.jar -c "SELECT Name as Title, Desc as Description FROM ${table_name}"

In bash or zsh terminal back-ticks are using to run commands.

Taron Qalashyan
  • 660
  • 4
  • 8