Issue
I'm constructing a Bash script to execute a MySQL query. The Bash scrip is very simple, but the query is not being executed correctly. MySQL responds like a do a mysql usage (help of commands). What am I doing wrong?
The bash file is:
COMANDO='mysql -h 148.72.64.68 -p******** -u root db_vias_ue -e "select count(*) from clientes"'
$COMANDO
Solution
Bash quoting rules are seriously weird. In what you wrote, the expression within double quotes actually gets separated into multiple arguments.
Try this:
COMANDO='mysql -h 148.72.64.68 -p******** -u root db_vias_ue -e "select count(*) from clientes"'
bash -c "$COMANDO"
Answered By - cidermole