[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: expr exit status
From: |
Philip Rowlands |
Subject: |
Re: expr exit status |
Date: |
Wed, 20 Jan 2010 11:33:58 +0000 (GMT) |
User-agent: |
Alpine 2.00 (DEB 1167 2008-08-23) |
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
- expr exit status, salih k, 2010/01/19
- expr exit status, salih k, 2010/01/20
- Re: expr exit status,
Philip Rowlands <=
- Re: expr exit status, salih k, 2010/01/20
- Re: expr exit status, Philip Rowlands, 2010/01/20
- Re: expr exit status, salih k, 2010/01/20
- Re: expr exit status, Eric Blake, 2010/01/20
- Re: expr exit status, Eric Blake, 2010/01/20
- Re: expr exit status, salih k, 2010/01/20