反引号无法在 shell 脚本中运行 mysql 查询 [英] backtick is not working to run mysql queries in shell script
本文介绍了反引号无法在 shell 脚本中运行 mysql 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从 shell 脚本运行 MySQL 查询.
Hi I am trying to run MySQL queries from shell script.
mysql -u root -p'1234' -e "CREATE TABLE $DB.aa_vv_cc
(
id int(10) unsigned NOT NULL AUTO_INCREMENT,
city varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
lat varchar(255) DEFAULT NULL,
`long` varchar(255) DEFAULT NULL,
status int(11) NOT NULL DEFAULT '1',
created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY ('id')
);"
我在long"上遇到错误.从 shell 脚本中反勾号不起作用.任何帮助将不胜感激.
I am getting error on "long".The back tick is not working from shell script.Any help will be appreciated.
推荐答案
反引号是 shell 中的 Command Substitution
.
Backticks are Command Substitution
in the shell.
并且它们在双引号字符串中进行评估.
And they are evaluated in double quoted strings.
所以外壳看到了
`long`
在您的字符串中并尝试运行命令 long
并且可能失败了.
in your string and trying to run the command long
and, presumably, failing.
你需要逃避反引号
\`long\`
在双引号字符串中以防止这种情况(或使用不评估它们的单引号字符串)
in the double quoted string to prevent that (or use a single quoted string which doesn't evaluate them)
'... `long` ...'
这篇关于反引号无法在 shell 脚本中运行 mysql 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文