KItis
KItis

Reputation: 5646

Error : Shell script returns unary operator is expected error message

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

Upvotes: 2

Views: 10869

Answers (3)

chemila
chemila

Reputation: 4361

try:

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

Upvotes: 0

Raphael Roth
Raphael Roth

Reputation: 27383

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

Upvotes: 1

codaddict
codaddict

Reputation: 455470

You need to quote $4:

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

Upvotes: 5

Related Questions