Syntax error on if statement in unix shell scripting: ksh: test: argument expected"

323 views Asked by At

Error on executing if statement in ssh command in unix shell scripting. Linux and sunos

#!/bin/bash
ssh u1@s1 "if [ $a == 100 ] 
then
echo Hey that is a large number
pwd
fi
date"

Error: Ksh: test: argument expected

1

There are 1 answers

2
glenn jackman On

You'll get this if $a is empty:

$ unset a
$ [ $a == 100 ] && echo one hundred || echo not
ksh: [: argument expected
not

Solution: quote the variable

$ [ "$a" == 100 ] && echo one hundred || echo not
not

Or use the double bracket conditional

$ [[ $a == 100 ]] && echo one hundred || echo not
not

I'm using ksh 93u+