qliq
qliq

Reputation: 11807

How to use a pair of single-quotes inside double qoutes in bash?

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.

Upvotes: 1

Views: 405

Answers (1)

Martin
Martin

Reputation: 38289

You need to use $ to dereference a variable. Change %USERNAME to $USERNAME and everything should work fine:

read USERNAME;
echo  "USE drupdb; SELECT uid  FROM users WHERE name= '$USERNAME';"

Upvotes: 1

Related Questions