LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-19-2005, 01:14 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 49
difference between exit 1 and exit


I learned that a proper way to exit from a shell script is by giving 'exit' in your shell script. Now, in some shell script examples I have seen people using 'exit 1' also.

What is the difference between these two i.e. 'exit' and 'exit 1'?

Thanks
 
Old 10-19-2005, 01:40 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Quote:
NAME
exit - End the application

SYNOPSIS
exit <returnCode>

DESCRIPTION
Terminate the process, returning returnCode to the system
as the exit status. If returnCode isn't specified then it
defaults to 0.
Exit codes are useful to programs that call your program. If your program finishes with exit code 0 then that generally means your program "succeeded". An exit code of 1 generally means that it failed. Maybe the program tried to open a file that didn't exist or something. This would tell the calling program that it might not want to continue.
 
Old 10-19-2005, 02:06 PM   #3
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 49
Thank you for providing the information.

How can I check the exit status code from my shell script?

Also, where did you find out that man page like description of the 'exit' command. I tried 'man exit' on my system but it did not find anything.
 
Old 10-19-2005, 02:08 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Try 'man n exit'.
 
Old 10-20-2005, 04:21 PM   #5
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Quote:
How can I check the exit status code from my shell script?
The $? env var holds the exit value of the last command.
 
Old 10-20-2005, 04:49 PM   #6
lowpro2k3
Member
 
Registered: Oct 2003
Location: Canada
Distribution: Slackware
Posts: 340

Rep: Reputation: 30
Quote:
Originally posted by ioerror
The $? env var holds the exit value of the last command.
yep.

[shell]$ ./yourscript
output...
[shell]$ echo $?
0
[shell]$
 
Old 10-20-2005, 04:56 PM   #7
ioerror
Member
 
Registered: Sep 2005
Location: Old Blighty
Distribution: Slackware, NetBSD
Posts: 536

Rep: Reputation: 34
Also, in zsh, one can put %? in PS1, so you get the exit value of the last command in the prompt (I do this). I don't know if bash has a similar option.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How do we use exit() alaios Programming 4 06-07-2005 10:44 AM
Can't exit X Moebius01 Mandriva 8 11-24-2003 08:47 PM
exit X ? w00t Linux - Newbie 11 06-01-2003 09:04 PM
exit xlord Programming 7 11-03-2002 12:33 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:42 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration