rap-2-h
rap-2-h

Reputation: 31978

Unix : Can't use backquote in MySQL command

I wrote a MySQL command in bash (Ubuntu) :

[XXXX:~]$ mysql -h localhost -u XXXX -pXXXX -e "DROP DATABASE IF EXISTS `f-XXXX`;"

I need backquote in this command, cause database name is variable.

That command doesn't work and it sends f-XXXX command not found I think my problem is related to backquotes. How can I do?

Upvotes: 3

Views: 383

Answers (2)

Incognito
Incognito

Reputation: 3094

You need not use backtick for variable substitution here.

[XXXX:~]$ mysql -h localhost -u XXXX -pXXXX -e "DROP DATABASE IF EXISTS ${DB};""

Upvotes: 1

Minesh
Minesh

Reputation: 2302

Bash takes the content of the backtick and runs another bash process with that as a command.

This is a backtick. Backtick is not a quotation sign, it has a very special meaning. Everything you type between backticks is evaluated (executed) by the shell before the main command (like chown in your examples), and the output of that execution is used by that command, just as if you'd type that output at that place in the command line.

Use $(commands) instead.

mysql -h localhost -u XXXX -pXXXX -e "DROP DATABASE IF EXISTS $('f-XXXX');"

Upvotes: 0

Related Questions