Bash Shell Exit Status

Exit status codes are helpful when creating shell scripts with IF statements. They are also helpful when you are trying to troubleshoot the outcome of a command. You can use "echo $?" to find out the exit status. In the terminal exit codes are not displayed on the screen by default, we have to echo them. Here are a few examples:

 grep "asda" test.log  

In this case we get no output. Now if we echo $? we should get an exit code:

$ grep "asda" test.log  

$ echo $? 1

In this case we get a "1"  which is a failure. "0" = Success, "2" = Incorrect Usage, "126" = Not Executable, "127" = Command Not Found.


Tagged under: bash, shell, exit codes