我有以下脚本:
#!/bin/sh
Q=`</dev/urandom tr -dc A-Za-z0-9 | head -c30`
mysql -uusername -ppasword accounts -e "update forum set key='$Q' where id='1';"
我必须在“forum”、“key”和“id”中添加反引号 (``),否则会返回错误:
ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key='xdindSG7hK9KaYgs9RISJNqrzmn4LJ' where id='1'' at line 1
但如果我添加反引号,bash 会将它们解释为变量。
我该怎么办?