return code of a unix command | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


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

return code of a unix command

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 08-02-2007
ramky79 ramky79 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 25 July 2014, 3:08 PM EDT
Posts: 106
Thanks: 2
Thanked 2 Times in 2 Posts
return code of a unix command

How to find out whether the command I executed is successful or unsuccessful(at commandlinet)

Eg:
say i execute the following command at command line
rm *
How do i find out whether my previous command is a success or failure.

Thankyou.

Best Regards,
Ram.
Sponsored Links
    #2  
Old 08-02-2007
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
 
Join Date: Feb 2004
Last Activity: 30 October 2014, 11:30 PM EDT
Location: NM
Posts: 10,253
Thanks: 285
Thanked 803 Times in 747 Posts
Note: rm * can be very dangerous, be careful


Code:
<some command>
echo "$?"

will display 0 if "some command" was successful. It will show 1 (or another non-zero number) if the command failed. Usually commands also display error messages when something goes wrong.
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Unix return code example khchong Shell Programming and Scripting 4 09-28-2011 02:33 AM
Managing awk return code over SSH command maverick72 Shell Programming and Scripting 11 09-23-2011 04:23 AM
Return code of command assigned to variable browndr Shell Programming and Scripting 2 08-05-2008 08:26 AM
to pick up the Return Code ( RC) from the mailx command and return it to SAS uisng 's manas6 UNIX for Dummies Questions & Answers 0 06-05-2008 06:44 AM
Move command return with exit code of 2 handak9 UNIX for Advanced & Expert Users 1 08-26-2004 05:40 AM



All times are GMT -4. The time now is 12:51 AM.