[英]Bash command variable assignment
如果我分配一个变量:
testThis='echo "This is a test"'
如果我使用$testThis
,它可以在脚本中运行。
但是,如果我想跳过一行怎么办? 所以我尝试:
testThis='echo; echo "This is a test"'
这失败了!
经过大量尝试$()
命令替换和各种引用后无法弄清楚。
不重新解析参数扩展。 以下
testThis='echo; echo "This is a test"'
$testThis
相当于
echo ';' echo \"This is a test\"
分号和双引号都是字符串的文字部分,而不是 shell 语法。 分词和去除引号后,shell 用六个 arguments 识别命令echo
显:
;
echo
"This
is
a
test"
使用 function 代替:
testThis () {
echo; echo "This is a test"
}
testThis
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.