我將參數存儲在變量中的命令中。最後一個命令我想要的是:在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