ammu
February 4, 2008, 11:35am
1
Hi
In an unix script I am using an Perl one liner perl -i -ne '-----'
If the perl one liner fails i am not able to catch the return code.
It always give 0 as return code. Can you tell me how can i catch the return code
perl -i -ne '---'
RETCODE=$?
echo $RETCODE
Thanks and Regards
Ammu
grumpf
February 4, 2008, 11:44am
2
works for me:
$ LANG=C ./test.sh
Can't open perl script "print hello": No such file or directory
2 <<= return code != 0
you can check success:
$perl -e 'print "hello\n" ' ; echo $?
hello
0
you can change the return value:
$perl -e 'print "hello\n"; exit 99; ' ; echo $?
hello
99
ammu
February 4, 2008, 1:57pm
3
Actually i am using the following perl onliner (to delete 1 and 2 line from the file)
perl -i -ne 'print unless 1..2' filename
echo $?
If i give a wrong file name too it gives return code it throws error and give return code 0