相关疑难解决方法(0)

如何执行存储为带引号和星号的字符串的bash命令

我尝试执行以下命令:

mysql AMORE -u username -ppassword -h localhost -e "SELECT  host  FROM amoreconfig"
Run Code Online (Sandbox Code Playgroud)

我把它存储在一个字符串中:

cmd="mysql AMORE -u username -ppassword -h localhost -e\"SELECT  host  FROM amoreconfig\""
Run Code Online (Sandbox Code Playgroud)

测试一下:

echo $cmd
mysql AMORE -u username -ppassword -h localhost -e"SELECT host FROM amoreconfig"
Run Code Online (Sandbox Code Playgroud)

尝试执行:

$cmd
Run Code Online (Sandbox Code Playgroud)

我得到了mysql的帮助页面:

mysql  Ver 14.14 Distrib 5.1.31, for pc-linux-gnu (i686) using readline 5.1
Copyright 2000-2008 MySQL AB, 2008 Sun Microsystems, Inc.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute …
Run Code Online (Sandbox Code Playgroud)

bash quotes scripting escaping

237
推荐指数
4
解决办法
24万
查看次数

标签 统计

bash ×1

escaping ×1

quotes ×1

scripting ×1