test command is not working

#!/bin/ksh
size=3978132853
limit=100
if [ $size -gt $limit ];then
echo exceeded limit
fi

This does not work though if i reduce 3978132853 to 397813285 it works any ideas and work around appreciated

(SunOS 5.9 Generic_117171-02 sun4u sparc SUNW,Ultra-80 )

Looks like integer overflow in the test. I get the same result on SunOS 5.6 but ksh on Aix 5.3 gives the right answer.

You could use bc to get round it, just test for a negative result after subtracting limit from size

size=3978132853
limit=100 
typeset -L1 res
res=$(($size - $limit))
if [ ! "$res" = "-" ]; then
  print exceeded limit
fi

:slight_smile: Thanks for the prompt reply. Your solution works just fine.