Bash不喜欢什么。什么应该逃脱?如何?
mysql --user=root --password=mypass vsftpd << EOF
GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO 'MYUSERNAME'@'%';"
EOF
我收到以下错误:
-bash: MYUSERNAME_%: command not found
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 '* TO 'MYUSERNAME'@'%'' at line 1
答案 0 :(得分:2)
反引号执行命令替换(与$()
相同)。尝试在外层使用单引号,并使用双引号作为用户名和主机名:
mysql --user=root --password=mypass vsftpd 'GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO "MYUSERNAME"@"%";'
您可以通过引用分隔符来指示此处doc不扩展变量,但我不确定这是否也适用于命令替换:
mysql --user=root --password=mypass vsftpd << 'EOF'
GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO 'MYUSERNAME'@'%';"
EOF