Bash and MySQL versions:
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
mysql Ver 14.14 Distrib 5.5.37, for debian-linux-gnu (x86_64) using readline 6.2
I have a bash script that tries to capture the result of a MySQL query to a variable using command substitution with the MySQL password as a variable that contains a dollar sign and no matter which way I try it, it always either fails authentication with access denied message or the query returns the MySQL help command text. I've tried dozens of different combinations of both types of command substitution and escaping characters till the cows come home. Here is an example:
PASS='pass$word'; RESULT=`mysql -u user -p'${PASS}' -h RemoteHostName DBName -e "select count(*) from TableName;"`; echo "${RESULT}";
This will return "Access denied for user"...
PASS='pass$word'; RESULT=`mysql -u user -p\'${PASS}\' -h RemoteHostName DBName -e \"select count\(*\) from TableName\;\"`; echo "${RESULT}";
This will return the MySQL help text
Any help would be much appreciated, thanks in advance.
RESULT=$(mysql -u user -p "${PASS}" -h RemoteHostName DBName -e "select count(*) from TableName;")
Will work as expected