LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
LinkBack Search this Thread
Old 04-21-2004, 10:24 AM   #1
liguorir
Member
 
Registered: May 2003
Posts: 256

Rep: Reputation: 30
Question Shell Scripting Exit(s)


What's the difference between

exit 0

and

exit 1

in shell scripting?
 
Old 04-21-2004, 10:42 AM   #2
Technoslave
Member
 
Registered: Dec 2003
Location: Northern VA
Posts: 493

Rep: Reputation: 30
Off the top of my head, it has to do with how the script has finished. I can't recall off the top of my head, but an exit 0 means that it quit successfully, and a 1 means there was an error.

Do a search for exit status shell or something like that in google, you should be able to find a better answer than mine :-D
 
Old 04-21-2004, 10:57 AM   #3
mfeat
Member
 
Registered: Aug 2003
Location: Akron, OH
Distribution: Fedora Core 3
Posts: 185

Rep: Reputation: 30
you can exit any code you want, the calling program can then access the return code as $?

example:

run_some_script

if [ $? -ne 0 ]; then
echo script failed
...
fi
 
Old 04-21-2004, 10:59 AM   #4
elluva
Member
 
Registered: Aug 2003
Location: Belguim, Ostend and Ghent
Distribution: Ubuntu
Posts: 600

Rep: Reputation: 30
Your answer was actually correct. When you run a program (or a script), it has an exit status. This is just an integer =/< 0. When running exit 0 in a shell script, you just set the shell variabel $? on 0. You can then use this in lets say an if:
Code:
if yourscript
then
  #Your exit status was 0
  do_something
else
  #Your exit status was > 0
  dosomeotherthing
fi
It is also possible to just 'echo $?', this will give you the exit status of last program run.
 
  


Reply


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell interface vs shell scripting? I'm confused jcchenz Linux - Software 1 10-26-2005 03:32 PM
How to get exit code of a progarm in Shell? neo_in_matrix Linux - Newbie 2 09-22-2005 01:46 PM
exit GDM to a shell PlatinumRik Linux - Software 2 04-18-2005 12:31 PM
How to exit Gnome to Shell, Mandrake 9.2? Ygarl Linux - Newbie 2 03-27-2004 09:47 AM


All times are GMT -5. The time now is 03:12 AM.

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