Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 09-22-2005, 12:18 PM   #1
Registered: Sep 2003
Posts: 52

Rep: Reputation: 15
How to get exit code of a progarm in Shell?

If want to know how to get the exit code of a program in shell scripts. Thanks.
Old 09-22-2005, 12:56 PM   #2
Senior Member
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 374Reputation: 374Reputation: 374Reputation: 374
The exit code is stored in a special variable: $?

I would suggest storing the exit status in a variable immediately after executing the command to avoid any confusion. For instance:

ls /opt > /dev/null

if [ ${exit_status} -eq 0 ] ; then
  echo "ls command completed successfully"
  echo "ls failed; exit status of ${exit_status}"
Old 09-22-2005, 01:46 PM   #3
Registered: Sep 2003
Posts: 52

Original Poster
Rep: Reputation: 15
Wow, thanks!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Exit Code: 7 dbzw SUSE / openSUSE 0 12-21-2004 01:06 PM
exit code 2 -- pppd eduac Linux - Software 3 11-21-2003 05:19 AM
atexit and exit code GŠutama Programming 3 11-01-2003 02:15 AM
pppd exit code = 10 eduac Linux - Hardware 1 10-20-2003 02:57 AM
kppp - exit code 1 grim1234 Slackware 3 09-02-2003 09:01 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:36 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration