Date: Tue, 16 Apr 2019 10:29:36 +0800 From: Paul Wise <pa...@bonedaddy.net> Message-ID: <5be7a3060ecb029ac36a4592bbee7fc071becd12.ca...@bonedaddy.net>
| I wonder if bash could set an additional variable to indicate if $? is | from a normal exit, a signal exit, a shell keystroke etc, That's really hard to do and do correctly. Eg: in (crashes && burns) assuming crashes exits with a signal, inside the subshell your new variable could be created, but where you care about the exit status is in the parent code, outside the sub-shell, and that subshell does not exit with a signal, rather it exits with the status of the last command that was run. That's 139 (or whatever). There's no way to pass variables back from a subshell, so what do you do now? Facilities that kind of work, sometimes, are worse that those that don't exist at all. kre ps: in that example, the "&& burns" is just there to prevent this from being a case where the shell running the subshell could simply do "exec crashes" in which case the parent would get the exit status directly from crashes, and could work out that it exited because of a signal. But with that extra conditional it cannot be done that way, the subshell needs to run crashes, wait for it to finish (exit because of a signal we are assuming) - which causes false as its status, so burns is not run (not attempted) and the shell exits with the exit status from crashes.