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.
Thanks for this! I am porting shell code from OpenVMS to Unix, and was searching for the equivalent to DCL’s $status.
Thanks!
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.
Thanks!
still useful 😀