Unix/Linux Go Back    

Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

return code of a unix command

Shell Programming and Scripting

Thread Tools Search this Thread Display Modes
Old Unix and Linux 08-02-2007
ramky79 ramky79 is offline
Registered User
Join Date: Sep 2006
Last Activity: 25 March 2015, 1:18 PM EDT
Posts: 107
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)

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


Best Regards,
Sponsored Links
Old Unix and Linux 08-02-2007
jim mcnamara jim mcnamara is offline Forum Staff  
Join Date: Feb 2004
Last Activity: 21 September 2017, 11:10 PM EDT
Location: NM
Posts: 11,181
Thanks: 560
Thanked 1,093 Times in 1,009 Posts
Note: rm * can be very dangerous, be careful

<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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux 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 09:39 AM.