我将参数存储在变量中的命令中。最后一个命令我想要的是:在bash变量内引用不受尊重
mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm
这里是我的尝试:
set -x # for debugging
RESULTDIR=results
MOCK_CONFIG="myconfig"
MOCK_ARGS="-r $MOCK_CONFIG --define \"debug_package %{nil}\" --resultdir $RESULTDIR"
cmd="mock $MOCK_ARGS --rebuild mypackage.src.rpm"
$cmd
的结果是:
+ RESULTDIR=results
+ MOCK_CONFIG=myconfig
+ MOCK_ARGS='-r myconfig --define "debug_package %{nil}" --resultdir results'
+ cmd='mock -r myconfig --define "debug_package %{nil}" --resultdir results --rebuild mypackage.src.rpm'
+ mock -r myconfig --define '"debug_package' '%{nil}"' --resultdir results --rebuild mypackage.src.rpm
ERROR: Bad option for '--define' ("debug_package). Use --define 'macro expr'
正如你所看到的,参数传递给--define
参数没有被正确引用。 --define
认为我只通过它debug_package
,这是不完整的。
我在尝试定义MOCK_ARGS
时引号中的各种变体,甚至试图摆脱debug_package
和%{nil}
之间的空格。
什么引号和/或转义组合允许我构建这个参数列表并执行该脚本中的命令?
编辑:
我存储在一个变量所得到的命令的原因是因为它最终被传递到其中做了一些记录的功能,然后执行该命令。
此外,我遇到this FAQ这表明我应该使用数组而不是变量。我已经开始尝试数组,但到目前为止还没有一个可行的解决方案。
这看起来像是http://stackoverflow.com/questions/954390/echo-nested-quotation-marks-in-tcsh的副本 – 2009-09-04 06:48:57
http://stackoverflow.com/questions/954390/echo- nested-quotation-marks-in-tcsh不适用于我。 – 2009-09-04 07:18:26
可能的重复[如何执行bash命令存储为带有引号和星号的字符串](http://stackoverflow.com/questions/2005192/how-to-execute-a-bash-command-stored-as-a -string-with-quotes-and-asterisk) – 2015-07-05 08:37:28