Bash Error Exit Status
Contents |
>ExampleComments1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero" and other impermissible operations2Misuse of
Bash Exit Codes
shell builtins (according to Bash documentation)empty_function() {}Missing keyword or command, or permission problem (and linux exit code diff return code on a failed binary file comparison).126Command invoked cannot execute/dev/nullPermission problem or command is not an executable
Bash Script Exit On Error
>127"command not found"illegal_commandPossible problem with $PATH or a typo128Invalid argument to exitexit 3.14159exit takes only integer args in the range 0 - 255 (see first footnote)128+nFatal error signal "n"kill -9 $PPID exit bash shell of script$? returns 137 (128 + 9)130Script terminated by Control-CCtl-CControl-C is fatal error signal 2, (130 = 128 + 2, see above)255*Exit status out of rangeexit -1exit takes only integer args in the range 0 - 255
exit codes, exit codes are important and this article describes how to use them in your scripts and understand them in general. Written by Benjamin Cane on 2014-09-02
Exit Code Python
14:45:00| 4 min read Sponsored by Lately I've been working on a lot
Bash Return Value From Function
of automation and monitoring projects, a big part of these projects are taking existing scripts and modifying them to be useful exit code 1 for automation and monitoring tools. One thing I have noticed is sometimes scripts use exit codes and sometimes they don't. It seems like exit codes are easy for poeple to forget, but they are http://tldp.org/LDP/abs/html/exitcodes.html an incredibly important part of any script. Especially if that script is used for the command line. What are exit codes? On Unix and Linux systems, programs can pass a value to their parent process while terminating. This value is referred to as an exit code or exit status. On POSIX systems the standard convention is for the program to pass 0 for successful executions and 1 or higher http://bencane.com/2014/09/02/understanding-exit-codes-and-how-to-use-them-in-bash-scripts/ for failed executions. Why is this important? If you look at exit codes in the context of scripts written to be used for the command line the answer is very simple. Any script that is useful in some fashion will inevitably be either used in another script, or wrapped with a bash one liner. This becomes especially true if the script is used with automation tools like SaltStack or monitoring tools like Nagios, these programs will execute scripts and check the status code to determine whether that script was successful or not. On top of those reasons, exit codes exist within your scripts even if you don't define them. By not defining proper exit codes you could be falsely reporting successful executions which can cause issues depending on what the script does. What happens if I don't specify an exit code In Linux any script run from the command line has an exit code. With Bash scripts, if the exit code is not specified in the script itself the exit code used will be the exit code of the last command run. To help explain exit codes a little better we are going to use a quick sample script. Sample Script: #!/bin/bash touch /root/
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the http://stackoverflow.com/questions/1101957/are-there-any-standard-exit-status-codes-in-linux workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join exit code them; it only takes a minute: Sign up Are there any standard exit status codes in Linux? up vote 210 down vote favorite 96 A process is considered to have completed correctly in Linux if its exit status was 0. I've seen that segmentation faults often result in an exit status of 11, though I don't know if this bash exit code is simply the convention where I work (the apps that failed like that have all been internal) or a standard. Are there standard exit codes for processes in Linux? If so, where can I find a list? linux exit-code share|improve this question asked Jul 9 '09 at 5:24 Nathan Fellman 46.1k61191269 2 if you're looking for the thing called "system error number" returned by system functions look here at errno –marinara Oct 21 '12 at 17:56 add a comment| 9 Answers 9 active oldest votes up vote 60 down vote accepted 8 bits of the return code and 8 bits of the number of the killing signal are mixed into a single value on the return from wait(2) & co.. #include