arabian_albert arabian_albert - 1 month ago 8
Bash Question

Getting unary operator error on Shell script Linux

I get this error:

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


Here is the script:

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


I don't understand what is wrong? This works perfectly locally but when I run it in a linux environment server I get this error...any help would be appreciated

Answer

You need more quotes.

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

...not...

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