函数foo以.bashrc
导出foo()
{
echo "run '$@'"
$@
}
export -f foo
作品
foo cmake --build .
run 'cmake --build .'
[ 10%] Built target main
...
不起作用
foo cmake -G "Unix Makefiles" -DARCHITECTURE_TYPE=armv7_32
run 'cmake -G Unix Makefiles -DARCHITECTURE_TYPE=armv7_32'
CMake Error: Could not create named generator Unix
...
答案 0 :(得分:1)
从不使用$@
无引号的原因;它与$*
完全相同。
foo () {
# including $@ in a longer quoted string can cause some
# weird side effects; I just use $* instead.
echo "run '$*'"
"$@"
}