I am going to write a bash script to manipulate user’s data on mysql DB.
Here is the problem. I need to pass a variable’s value into a Mysql query string:
read USERNAME;
echo "USE drupdb; SELECT uid FROM users WHERE name= '%USERNAME';" > /tmp/query.sql ;
Whatever combinations that I’ve used (including backslashs befor single-quotes to scape them) did not do the trick. I still get something other than the value of %USERNAME inside the query.sql.
I appreciate your hints.
You need to use
$to dereference a variable. Change%USERNAMEto$USERNAMEand everything should work fine: