The "if" itself resets $? to 0, unless it executes the then or
else branch, in that case the exit status of the branch remains set.
Yeah, I know that. For some reason I thought you were saying something
else. Re-reading your message I can't imagine what I was thinking.
Please attribute it to a tired brain.
I know no solution for reusing the $? short of storing the contents $?
away in a variable right after the command that set it.
Agree completely. I do it all the time! Sorry for the off-topic
diversion.
Steve