I want to save the exit status of the last ran command (in a file, in a variable, it doesn't really matter), but this must be done automatically in an interactive shell, manually running something like
var=$? is not an option.
I decided to try to use
PROMPT_COMMAND to accomplish this. Below you can see me proving that what I tried didn't work.
/home/exit_status$ export PROMPT_COMMAND="echo $?" 0 /home/exit_status$ rm / rm: cannot remove ‘/’: Is a directory 0 /home/exit_status$ echo $? 1 0
How do I go about making it so that the snippet above works as I intend? I can work out how to store it, I don't need help with that. I just mentioned that to give context.