Operating System - HP-UX
1828451 Members
3650 Online
109978 Solutions
New Discussion

Re: queries on command 'exit [n] '

 
SOLVED
Go to solution
Henry Chua
Super Advisor

queries on command 'exit [n] '

Hi guys,

for "exit n" command, what does the n signifies.. i only knows that the program exit with that specific status. but what does this means

does n= 0, 1, 2 3.... each having an unique meaning when passed on with exit?

what is the different if I exit with 0 or 1?

thank u =)
3 REPLIES 3
Sanjay Kumar Suri
Honored Contributor

Re: queries on command 'exit [n] '

exit command to leave a shell program with a certain exit status. The default exit (no arguments) will exit the shell program with the status of the last command executed. Refer man pages on exit.

The usual exit statuses are:

0 Success.
1 A built-in command failure.
2 A syntax error has occurred.
3 Signal received that is not trapped

sks
A rigid mind is very sure, but often wrong. A flexible mind is generally unsure, but often right.
Paul_481
Respected Contributor

Re: queries on command 'exit [n] '

Hi Henry,

I guess it do not have any special meaning since it is define. One purpose I can see we this is when in a very nested program you can easily identify where did you program exit which the value of $? could be use with other program.

my 2 cents.

Regards,
Paul
Biswajit Tripathy
Honored Contributor
Solution

Re: queries on command 'exit [n] '

Whan a script exists with status 'n' (i.e exit n), the
script returns 'n' to the shell that invokes the script.
Typically, an exit status of 0 is considered success
and non zero as failure.

For example, consider this simple script (let's
call it exit_demo):

-- Start script exit_demo --------
# Demo script
exit $1
----- End script

Now run this script and check exit status:
# exit_demo 0
# echo $?
0
# exit_demo 5
# echo $?
5

Did I explain that clearly?

- Biswajit


:-)