Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm new to Unix.

Just want to know what is exit 99 and why would one use it and what are the significance uses of it.

For example, I'm using exit 99.

share|improve this question
    
I knew I loved you at exit 99. –  Nick T Apr 17 at 16:32
    
Pretty much similar answer to SO: "Why return a negative errno? (e.g. return -EIO)" –  smci Apr 18 at 6:51

5 Answers 5

up vote 21 down vote accepted

There is no significance to exiting with code 99, other than there is perhaps in the context of a specific program.

Either way, exit exits the shell with a certain exit code, in this case, 99. You can find more information in help exit:

exit: exit [n]
    Exit the shell.

    Exits the shell with a status of N.  If N is omitted, the exit status
    is that of the last command executed.
share|improve this answer
2  
Hey Thanks for the info!! –  Java_Alert Apr 17 at 8:08
4  
Not quite - 99 is not zero, and so indicates that the program failed for some reason. –  psusi Apr 17 at 13:35
3  
@psusi There are plenty of non-zero exit codes in applications that are not to do with failure, but indicate other execution conditions (many programs use it to indicate falsiness or non-optimal execution rather than failure, for example). To assert that a certain exit status must indicate failure without knowing the program is simply not true. I won't speculate on the meaning of "99" in some unknown program. –  Chris Down Apr 17 at 18:24
1  
The shell, and most other tools, including make, treat any non zero exit value as an error. –  psusi Apr 17 at 19:23
1  
Except for these only indicate failure in isolation, not in larger context of checking for truthiness. Either way, I refuse to speculate on the meaning of some exit code when the application is not defined. –  Chris Down Apr 20 at 9:14

In addition to @Chris Down, there is some return code that reserved for the shell, they have special meaning:

RETVAL   Meaning

1        General errors
2        Misusage
127      Command not found

You can refer to this for more details.

share|improve this answer
    
Thanks for the additional points. –  Java_Alert Apr 17 at 8:09
    
@MrLister: Yeap, my mistypo, fixed! –  Gnouc Apr 17 at 9:33
    
there is still a s missing in there ("Misuage"?) –  ratchet freak Apr 17 at 10:06

There is a very long-standing convention (in Unix) for return-status ranges:

  • 0 means success
  • positive numbers mean minor problems, but essentially the task completed
  • negative numbers mean critical error (e.g. disk-full, file-not-found)

Exactly what those individual positive and negative numbers mean is up to the programmer. Sometimes you can choose them for compatibility with other similar programs (e.g. Gnu tools). @Gnouc lists some.

No, I'm not aware of any special significance to exit code 99, never seen it used. Maybe it means 'Not enough beer'

See:

share|improve this answer
    
I never heard of that Unix convention. And your two references do not support your assertion about that convention. –  fpmurphy1 Apr 20 at 14:06
    
The first reference does. There are 1.67m google hits on unix return status positive negative numbers. –  smci Apr 20 at 20:17
    
There are a small number of negative return values specified in POSIX.1 but these are for programming APIs –  fpmurphy1 Apr 25 at 0:02

Normally, if you finish your script at some point with:

exit 0

The shell will get a 0 as the return code. This zero means everything was OK.

However, if your program has found some error condition, you should exit with a non-zero return code, to inform the shell that something has gone wrong. If you don't want to be more specific, you can simply use 1.

exit 1

You can however, inform the shell of particular type of failures by using other numbers. For example, bash itself returns a 127 for program not found. So if you document the behaviour of your script, you can do something useful after running it by checking the value of the special variable $?, which holds the return code of the last executed program.

I looked into this a while ago and found that, for example, FreeBDS had some very useful conventions with regards to exit codes, documented in man 3 sysexits

share|improve this answer
1  
"The shell will get a 0 as the return code" wrong, exit without parameters exits with the status code of the last command run. (see pubs.opengroup.org/onlinepubs/009695399/utilities/exit.html) –  Matteo Italia Apr 18 at 7:07
    
Thank you, long standing misconception of mine, will fix the answer. –  Jacobo de Vera Apr 22 at 7:24
    
Great, downvote removed :) –  Matteo Italia Apr 22 at 7:36

Some programmers will supply a lot of different errorcodes starting with 1. New versions might introduce new specific errorcodes, so which code should be used for
"all other errors / unspecified error" ? The exit codes will be truncated at 255, so I would choose 99 as an "other error".

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.