Linux bash (or other shell.) Have you ever fat fingered "echo $?" into something like "echo $4" thereby permanently preventing you from knowing the return code for the previous command? I do this often (and it's so annoying), so I figured I'll ask: does bash and/or linux have a "return code stack" or array or something that holds the return codes from previous commands, not just the last one that you ran? I'm talking about simple commands not involving pipes.
If you want to see return codes for interactive bash you can use the PROMPT_COMMAND variable like this:
The commands in this variable are executed after every command. It should only contain bash internal commands. In my example it shows the $? if it is not 0 and the signal if the previous command was killed by a signal.