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

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



Solution 1:[1]

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+

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 glenn jackman