Peng Yu
2018-12-05 17:50:54 UTC
Hi,
I'd expect that `false` below is trapped independent from whether `f `
is used with `||` or not. But it doesn't do so.
The manual does not discuss the set -E case explicitly, but I think
that it is better not to change the behavior of trap ERR in nonlocal
places. Is this a design issue that worth reconsidering? Thanks.
$ cat main.sh
set -E
trap 'echo in ERR trap' ERR
function f {
echo BEGIN
false
echo END
}
f
f || true
echo xxx
set -v
false || true
$ ./main.sh
BEGIN
in ERR trap
END
BEGIN
END
xxx
false || true
====
The ERR trap is not executed if the failed command is part of the
command list immediately following a while or until keyword, part of
the test in an if statement, part of a command executed in a && or
|| list except the command following the final && or ||, any command
in a pipeline but the last, or if the command's return value is
being inverted using !. These are the same conditions obeyed by the
errexit (-e) option.
I'd expect that `false` below is trapped independent from whether `f `
is used with `||` or not. But it doesn't do so.
The manual does not discuss the set -E case explicitly, but I think
that it is better not to change the behavior of trap ERR in nonlocal
places. Is this a design issue that worth reconsidering? Thanks.
$ cat main.sh
set -E
trap 'echo in ERR trap' ERR
function f {
echo BEGIN
false
echo END
}
f
f || true
echo xxx
set -v
false || true
$ ./main.sh
BEGIN
in ERR trap
END
BEGIN
END
xxx
false || true
====
The ERR trap is not executed if the failed command is part of the
command list immediately following a while or until keyword, part of
the test in an if statement, part of a command executed in a && or
|| list except the command following the final && or ||, any command
in a pipeline but the last, or if the command's return value is
being inverted using !. These are the same conditions obeyed by the
errexit (-e) option.
--
Regards,
Peng
Regards,
Peng