On Wed, 20 Jan 2010, salih k wrote:

add_num=`expr $int_num + 1 1>/dev/null 2>&1`

       if [ "$?" -ne "0" ]

some case exit status is 1552 for expr even though the argument is integer

This cannot be true, as the exit status exposed through the $? shell variable is limited to the range 0-255. For example,

$ sh -c 'exit 255'; echo $?
255
$ sh -c 'exit 1552'; echo $?
16

As Eric has (patiently) explained there are better ways in shell to test for an integer, so I'd suggest using those.

For reference, this is what expr will do with various inputs:

$ expr 5 + 1 >/dev/null; echo $?
0

$ expr -1 + 1 >/dev/null; echo $?
1

$ expr fish + 1 >/dev/null; echo $?
expr: non-numeric argument
2


Cheers,
Phil


Reply via email to