help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Help-bash] trap ERR in || with set -E enabled


From: Peng Yu
Subject: [Help-bash] trap ERR in || with set -E enabled
Date: Wed, 5 Dec 2018 11:50:54 -0600

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.

-- 
Regards,
Peng



reply via email to

[Prev in Thread] Current Thread [Next in Thread]