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:
Given the nature of this variable (no one indexes text like ‘$?’), it’s annoyingly hard to Google for.
5 Replies to “check last exit status code in bash shell”
Thanks for this! I am porting shell code from OpenVMS to Unix, and was searching for the equivalent to DCL’s $status.
Hey, if you’re trying to help people searching for “$?”, you should tag the post with the phrase(s) people might search for. Bash dollar sign question mark!
And thanks by the way, this is what I was looking for.
still useful 😀