开发者

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 开发者_JS百科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 %USERNAME to $USERNAME and everything should work fine:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜