Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: errexit and (Z)ERR trap regression



On Fri, Jun 21, 2024, at 4:36 PM, Bart Schaefer wrote:
> On Fri, Jun 21, 2024 at 1:03 PM Lawrence Velázquez <larryv@xxxxxxx> wrote:
>>
>> The full description of "set -e" in the fresh-out-of-the-oven
>> POSIX.1-2024 is:
>>
>>         This requirement applies to the shell environment and each
>>         subshell environment separately.  For example, in:
>>
>>                 set -e; (false; echo one) | cat; echo two
>>
>>         the `false' command causes the subshell to exit without
>>         executing `echo one'
>
> Hm, that doesn't directly address something like
>
>   set -e; true && (false; echo one) || echo two
>
> If the subshell should execute "echo one" then the parent should not "echo two".

Right, because early exit is suppressed in the non-final portions
of the AND-OR list and is not reenabled in the subshell.  All of
bash, dash, ksh, mksh, yash, and the Solaris 10 Bourne shell print
"one" here.

> Unfortunately I don't follow how any of the POSIX.1-2024 text is meant
> to apply to
>
>    set -e; true && { false; echo one; } || echo two
>
> Is "false" there considered to be "any command of an AND-OR list" ?

This ought to work the same as the subshell version: early exit is
suppressed for the commands "true" and "{ false; echo one; }", so
the overall output is still "one".  The aforementioned shells behave
this way.

-- 
vq




Messages sorted by: Reverse Date, Date, Thread, Author