在一个bash文件s.sh
中,我有一个Executor函数,我传递要执行的命令。每当某个命令不能按预期工作时,此功能将输出该命令。Bash函数不执行输入命令
Executor()
{
if ! $*
then
echo "$*"
exit 2
fi
}
现在我调用这个函数 -
Executor clangPath="Hello" make
(这是用来设置clangPath变量的值,如“你好”,在生成文件)
这造成了一个错误 -
./s.sh: line 5: clangPath=Hello: command not found
[./s.sh] Error: clangPath=Hello make
但是执行这样的命令一样正常工作
if ! clangPath="Hello" make
then
echo "HelloWorld!"
fi
看着错误后,我认为有可能是用字符串的报价错误,所以我想
exitIfFail clangPath='"Hello"' make
即使这导致了一个错误 -
./s.sh: line 5: clangPath="Hello": command not found
[./s.sh] Error: clangPath="Hello" make
有什么事情是错误的原因?
你可以试试!/usr/bin/ksh $ * ...取决于你在哪里和使用什么shell?我没有能力在这里测试。 – FreudianSlip
参见[Bash FAQ 050](http://mywiki.wooledge.org/BashFAQ/050)。 – chepner
Eww,'$ *'...我认为你拼错了'“$ @”'。 –