Assigning numeric values to variable

I have a code like this

v_num=9
 comp_num=39
 if [$v_num -gt $comp_num] 
 then
 echo "pass"
 fi
 echo "end"

I am getting an error

ksh: [9: not found
end

When I change the code to

v_num=99
 comp_num=39
 if [$v_num -gt $comp_num]
 then
 echo "pass"
 fi
 echo "end"

I am getting error
ksh: [99: not found
end

I guess the constants are not getting recognized.
Please help

you should give the space in the condition..

if [ $v_num -gt $comp_num ] 
1 Like

Please use spaces between square brackets.

if [ $v_num -gt $comp_num ] 
1 Like

spacing around your tests (the square brackets need to be separate tokens

a=9
b=10
if [ a -gt b ]
then
  echo what now
else
  echo that makes sense
fi
1 Like