The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Return codes of RDIST vishal_ranjan HP-UX 0 06-06-2007 02:01 AM
Return Codes kris01752 UNIX for Advanced & Expert Users 3 09-25-2006 09:40 AM
Return codes Bab00shka UNIX for Dummies Questions & Answers 4 02-02-2006 09:46 AM
Help with Return codes leezer1204 UNIX for Dummies Questions & Answers 1 04-26-2005 09:10 AM
return codes from rsh commands... bbouch UNIX for Dummies Questions & Answers 1 02-20-2002 03:03 PM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jul 2006
Posts: 55
help with return codes

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
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: May 2006
Posts: 95
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
Reply With Quote
  #3 (permalink)  
Old 02-04-2008
Registered User
 

Join Date: Jul 2006
Posts: 55
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
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 10:30 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0