[英]proper expand command line parameter in bash
I want to display what I'm running, but when the commands contain space parameter, it failed.我想显示我正在运行的内容,但是当命令包含空格参数时,它失败了。
#!/bin/bash
go() {
echo "*** $*"
$* || exit 1
}
go make NAME="Hi Here"
That will get wrong behavior like那会得到错误的行为,比如
make NAME=Hi Here
Is there any better method to improve the go() function?有没有更好的方法来改进 go() 函数?
Replace $* with "$@":将 $* 替换为 "$@":
#!/bin/bash
go() {
echo "*** $*"
"$@" || exit 1
}
go make NAME="Hi Here"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.