1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2024-12-28 04:05:12 +01:00

52977: ERR_EXIT/ERR_RETURN are respected by the final command in && / || lists

This commit is contained in:
Philippe Altherr 2024-06-28 21:05:42 -07:00 committed by Bart Schaefer
parent 98a877d32c
commit da733f5df6
2 changed files with 28 additions and 0 deletions

View file

@ -1568,6 +1568,7 @@ execlist(Estate state, int dont_change_job, int exiting)
}
state->pc = next;
code = *state->pc++;
noerrexit = oldnoerrexit;
}
state->pc--;
sublist_done:

View file

@ -995,6 +995,33 @@ F:Must be tested with a top-level script rather than source or function
?loop 0
?loop 1
( set -e; true && {false; echo NOT REACHED} )
( trap "print Trapped!" ERR; true && {false} )
( trap "print Trapped!" ERR; true && if true; then false; fi )
( trap "print Trapped!" ERR; true && {false} always {true} )
( true && (set -e; false; echo NOT REACHED) )
( true && (trap "print Trapped!" ERR; false) )
( true && { set -e; false; echo NOT REACHED } )
( true && { trap "print Trapped!" ERR; false } )
( set -e; true && (false; echo one) || echo two )
( set -e; true && { false; echo one; } || echo two )
0:ERR_EXIT is triggered by last command in an AND-OR list
>Trapped!
>Trapped!
>Trapped!
>Trapped!
>Trapped!
>one
>one
( set -o ERR_RETURN; f() { false; echo NOT REACHED; }; f || true; echo OK )
( set -o ERR_RETURN; f() { true && false; echo NOT REACHED; }; f || true; echo OK )
( set -o ERR_RETURN; f() { true && { false }; echo NOT REACHED; }; f || true; echo OK )
0:ERR_RETURN is triggered in function calls on the left of an AND-OR
>OK
>OK
>OK
if zmodload zsh/system 2>/dev/null; then
(
trap 'echo TERM; exit 2' TERM