在 bash 文件s.sh
中,我有一个 Executor 函数,我将要执行的命令传递给该函数。每当某些命令未按预期工作时,此函数就会输出该命令。
Executor()
{
if ! $*
then
echo "$*"
exit 2
fi
}
现在我正在调用这个函数 -
Executor clangPath="Hello" make
(这用于在makefile中将clangPath变量的值设置为“Hello”)
这导致了一个错误 -
./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
错误的原因可能是什么?