Skip to content
 

check last exit status code in bash shell

In case you’re curious (while debugging a program or a script) about the exit status code returned by the last shell command you ran, the incantation to retrieve it in the bash shell is:

echo $?

Given the nature of this variable (no one indexes text like ‘$?’), it’s annoyingly hard to Google for.

One Comment

  1. Pete says:

    Thanks for this! I am porting shell code from OpenVMS to Unix, and was searching for the equivalent to DCL’s $status.

Leave a Reply