Home > Bash Error > Bash Error Codes

Bash Error Codes


More realistically, 0 means sucess or maybe failure, 1 means general failure or maybe sucess, 2 means general failure if 1 and 0 are both used for sucess, but maybe sucess share|improve this answer edited Dec 17 '15 at 12:19 mikeserv 37k341109 answered Nov 11 '15 at 15:03 PSkocik 12.7k12561 I do wonder if there's anything like a mapping between Script: #!/bin/bash touch /root/test If we remove the echo command from the script we should see the exit code of the touch command. Notice also that you don't need to do: command1 if [ $? -ne 0 ]; then You can simply say: if ! http://waspsoft.com/bash-error/bash-error-codes-list.html

The two lines change the working directory to the name contained in $some_directory and delete the files in that directory. Using parameter expansion, it is possible to perform a number of useful string manipulations. Assuming you've named the above exit.sh generator exit.sh.sh, the code for exit2str can be generated with (exit2str.sh.sh) : #!/bin/sh echo ' exit2str(){ case "$1" in' ./exit.sh.sh | sed -nEe's|^(S_)?EX_(([^_=]+_?)+)=([0-9]+).*|\4) echo "\1\2";;|p' If so, where can I find a list?

Bash Get Exit Status

Not the answer you're looking for? Not the answer you're looking for? try { echo 'Hello' try { echo 'Nested Hello' false echo 'This will not execute' } catch { echo "Nested Caught (@ $__EXCEPTION_LINE__)" } false echo 'This will not execute too' On top of those reasons, exit codes exist within your scripts even if you don't define them.

  1. It is true, however, that you say "Bourne" and not "Bourne-derived" (although you do include ksh93). –Dennis Williamson Nov 10 '15 at 18:21 2 This answer appears to be very
  2. returns 137 (128 + 9) #255* Exit status out of range exit -1 exit takes only integer args in the range 0 - 255 EOF $(which kill) -l |tr ' '
  3. being interpreted as 0 in a classic shell.
  4. share|improve this answer answered Jul 9 '09 at 5:28 segfault 3,06463255 1 It look like you both answered in the same minute.
  5. I guess the reason is that you have lots of *conf files in /etc and no *conf files in /usr.
  6. Improving the error exit function There are a number of improvements that we can make to the error_exit function.
  7. command1; then share|improve this answer edited Sep 23 at 17:57 answered Jul 10 '15 at 18:37 dimo414 20.2k774118 2 Thanks for the if !
  8. UNIX is a registered trademark of The Open Group.
  9. This should not cause any problems, since there is no overlap or conflict in usage of exit codes between compiled C/C++ binaries and shell scripts.


comments powered by Disqus Benjamin is a Systems Architect working in the financial services industry focused on platforms that require Continuous Availability. Not the answer you're looking for? My home country claims I am a dual national of another country, the country in question does not. Linux Exit Code There is no full list of all exit codes which can be found, however there has been an attempt to systematize exit status numbers in kernel source, but this is main

Segmentation fault 139 $ expr 139 - 128 11 If you're seeing anything other than this, then the program probably has a SIGSEGV signal handler which then calls exit normally, so In addition to the one you mention, I know of: the BSDs have sysexits.h which defines meanings for values from 64 on up. Aside from the trivial exceptions of false and test, which are both designed to give 1 for sucess, there's a few other exceptions I found. That's the intended behavior.

Reserved Exit Codes

Exit Code NumberMeaningExampleComments1Catchall for general errorslet "var1 = 1/0"Miscellaneous errors, such as "divide by zero" Linux Exit Status Why don't most major game engines use gifs for animated textures? up vote 5 down vote favorite 4 Is there a way I can do what stated in the title from the terminal commands, or will I have to look into the Example: $ exit 3.14159 -bash: exit: 3.14159: numeric argument required 128-254 - fatal error signal "n" - command died due to receiving a signal.

Exit 127

sh: line 0: exit: 3.14159: numeric argument required 255 According to the above table, exit codes 1 - 2, 126 - 165, and 255 have special meanings, and should therefore be 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 Bash Get Exit Status I’ve quoted the relevant POSIX specifications (emphasis mine): Exit Status for Commands Each command has an exit status that can influence the behavior of other shell commands. Bash Error Status Yes, of course I'm an adult!

Are there standard exit codes for processes in Linux? weblink It is also important that your scripts return a meaningful exit status when they finish. It seems to date back to at least 1993 and some big projects like Postfix use it, so I imagine it's the way to go. STATUS_STACK_OVERFLOW). Bash Exit 2

exit / exit status

#!/bin/bash echo hello echo $? # Exit status 0 returned because command executed successfully. GNU grep documents that exit code 0 means at least one match was found, 1 means no matches were found, and 2 means an I/O error occurred; this convention is obviously The list constructs use exit codes to understand whether a command has successfully executed or not. navigate here Ending a script with exit 127 would certainly cause confusion when troubleshooting (is the error code a "command not found" or a user-defined one?).

Execution: $ ./tmp.sh touch: cannot touch '/root/test': Permission denied $ echo $? 1 As you can see, since the last command run was touch the exit code reflects the true status Bash Error Code 255 Within a script, an exit nnn command may be used to deliver an nnn exit status to the shell (nnn must if [ $status -ne 0 ]; then echo "error with $1" >&2 fi return $status } mytest $command1 mytest $command2 share|improve this answer edited Apr 21 at 21:45 octopusgrabbus 5,55772882 answered

What type of sequences are escape sequences starting with "\033]" Are there any 'smart' ejection seats?

How could banks with multiple branches work in a world without quick communication? Exit Codes With Special Meanings at Advanced Bash-Scripting Guide Writing Better Shell Scripts – Part 2 at Innovationsts share|improve this answer edited Sep 7 at 8:19 answered Jan 11 at 23:54 share|improve this answer edited Jul 9 '09 at 5:48 answered Jul 9 '09 at 5:43 Dean Povey 6,26212444 add a comment| up vote 2 down vote When Linux returns 0, it Bash Error Code Of Previous Command How to deal with a very weak student?

Third: The exit statuses of the shell, for example bash. In my opinion the author of the page you linked is making an unsupported assertion that the listed exit codes are reserved based, apparently, on the fact that the shell itself Realism of a setting with several sapient anthropomorphic animal species Good way to explain fundamental theorem of arithmetic? his comment is here Thanks :) –jwbensley Mar 26 '11 at 23:11 4 Wouldn't the exit code returned by test() always return 0 in case of an error since the last command executed was

The 11 on segfault is interesting, as 11 is the signal number that the kernel uses to kill the process in the event of a segfault. more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed It's not, if nothing goes wrong. It is exit status of ls.

Can filling up a 75 gallon water heater tank without opening a faucet cause damage? You can't count on any given program obeying any particular one of these conventions. You can read more about parameter expansion in the bash man page under the topic "EXPANSIONS". Problem?

Symbolic comparison of recursive functions Is there a way to make a metal sword resistant to lava? It can also return a value, which is available to the script's parent process.

Every command returns an exit status (sometimes referred to as a return status

You can surround a variable name with curly braces (as with ${PROGNAME}) if you need to be sure it is separated from surrounding text. The more command and the spell command give 1 for failure, unless the failure is a result of permission denied, nonexistent file, or attempt to read a directory. Why write an entire bash script in functions? Is my workplace warning for texting my boss's private phone at night justified?