2012-08-07 45 views
0

这是我的代码:为什么我的shell在-a条件下工作良好?

echo $1 $2 
    if [ "Release"!="$2" -a "Debug"!="{$2}" ]; then 
     echo "error! the arg of -c must be \"Release\" or \"Debug\" !" 
     exit 1 
    fi 
    XCODECONFIG="$2"; 

当我输入

./build.sh a Release 

输出是:“错误-c的ARG必须是 “

a Release 
    error! the arg of -c must be "Release" or "Debug" ! 

它打印版本”或“调试”!“为什么不继续使用XCODECONFIG =“$ 2”?

回答

2

必须有空格周围!=

[ "Release" != "$2" -a "Debug" != "{$2}" ] 

当你写你的表达没有空格,它是syntaticaly正确的,但这意味着其他的事情。它看起来像:

[ STR1 -a STR2 ] 

在你的情况,有!=里面,但这并不意味着什么;无论如何,这只是字符串;每个字符串评估为true,并且True -a True也将评估为true。在shell脚本

2

空间问题,请尝试:

if [ "Release" != "$2" -a "Debug" != "{$2}" ]; then

否则你的表情也只是评估串两个大块其中既有truthy值,因此如果执行

相关问题