在Shell脚本Linux上获得一元运算符错误

时间:2016-10-25 15:21:42

标签: linux shell scripting

我收到此错误:

getengine.sh: line 38: [: =: unary operator expected
getengine.sh: line 41: [: =: unary operator expected

这是脚本:

if [ $1 = "m" ]; then #this is line 38
    initial=`curl -s http://some/2016/30-publish`
    label=`curl -s http://test/${initial}.l/artifacts/info.xml`
elif [ $1 = "s" ]; then # this is line 41
    initial=`curl -s http://some/2016/30-publish`
    label=`curl -s http://test/${initial}.l/artifacts/info.xml`
fi

我不明白出了什么问题?这在本地完美运行,但是当我在linux环境服务器中运行时,我收到此错误...任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

您需要更多报价。

# this is correct
[ "$1" = "m" ]

...不...

# WRONG: this becomes [ = m ] if $1 is empty, producing your error.
[ $1 = "m" ]