The POSIX shell standard gives three exceptions to the application of set -e:
- The failure of any individual command in a multi-command pipeline shall not cause the shell to exit. Only the failure of the pipeline itself shall be considered.
- The -e setting shall be ignored when executing the compound list following the while, until, if, or elif reserved word, a pipeline beginning with the ! reserved word, or any command of an AND-OR list other than the last.
- If the exit status of a compound command other than a subshell command was the result of a failure while -e was being ignored, then -e shall not apply to this command.
I'm struggling to understand the meaning of (3); is it referring to something like:
set -e { false; } && : ( false ) && : Here, { false; } is a non-subshell compound command with an exit status of 1. The exit status resulted from the "failure" of false. set -e is being ignored while executing false because it's not the last command of an AND-OR list. The same applies to ( false ), but it's a subshell command, so is set -e allowed to apply to it in the parent shell and thus exit?
This doesn't seem to be the case in actual shells, so I'm pretty sure this example is not what (3) is talking about. After all, it would mean things like if ( false ); then :; fi could exit when executing the if condition. But, it seems the only contexts in which set -e is being ignored are defined by (2), so when then could (3) apply in a logical way?
Essentially, what is an example that clearly demonstrates the meaning of (3), both in what it applies to and why it makes a distinction for subshells?