Error : Shell script returns unary operator is expected error message

10,812

Solution 1

You need to quote $4:

if [ "$4" == "managed?.out" ];then

Solution 2

change the if statement to

if [ "$4" == "managed?.out" ];then

The double-quotes are only necessary as you use $4, if your variable would be $string, you would not need them.

should "?" be interpreted as a bash-wildcard? if yes, you need to use

if [[ "$4" == managed?.out ]];then
Share:
10,812
KItis
Author by

KItis

software engineer

Updated on June 05, 2022

Comments

  • KItis
    KItis almost 2 years

    i am fixing a given shell script and i am getting following error message

    line 322: [: ==: unary operator expected
    

    this error is returned from this line.

     if [ $4 == "managed?.out" ];then
    

    could someone explain me what makes this error

    Also could someone explain what is the purpose of using ? in the"managed?.out"

    thanks in advance for any help