I’m having difficulty locating a comprehensive up-to-date list of error codes from Bash. e.g.:
$ udevadm info /dev/sdx; echo Exit code $? Unknown device, --name=, --path=, or absolute path in /dev/ or /sys expected. Exit code 4
How is one supposed to look up such exit codes?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
There are a handful of exit codes with reserved special meanings:
Exit Code Number Meaning 1 Catchall for general errors 2 Misuse of shell builtins (according to Bash documentation) 126 Command invoked cannot execute 127 "command not found" 128+n Fatal error signal "n" 130 Script terminated by Ctrl-C 255* Exit status out of range
Everything below 125 is fair game for developers, and can really only be divined, as l0b0 notes in his answer, by reading the man page for the application, or the source code, to determine what the code signifies (if, indeed, it is documented at all).
Method 2
tl;dr Exit codes are application specific.
There are some loose conventions. false and anything successful prefixed with ! (like ! true) in POSIX shells return exit code 1, but a developer can use any exit code between 0 and 255 for whatever they want. Ultimately you have to look at its documentation (in the best case) or the code (in the worst case) to know what it means. For programs with man pages exit codes will often be listed in a section named EXIT STATUS (GNU tools like find).
Some popular meanings are listed in /usr/include/sysexits.h – I try to use them whenever possible. As @AnsgarEsztermann points out, these are not a Bash reference, or even an application reference except for those who choose to use it (C/C++ developers primarily according to the ABS).
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0