Bash 4.1 does not set the ERR trap:

$ env -i HOME="$HOME" TERM="$TERM" bash3 <<\!

 set -o errexit
 set -o errtrace

 TRIGGERED_ERR() { return $?; }

 trap 'TRIGGERED_ERR' ERR

 set -o xtrace

 var=$(false) || true
 echo $?

 var=$(false || true) # only way of not triggering it...
 echo $?

!

++ false           # Subshell false
+++ TRIGGERED_ERR  # Ignores outer "|| true"
+++ return 1
+ var=
+ true
+ echo 0
0                  # But the entire command line does
                  # not set off errexit
++ false
++ true            # Predictable second subshell...
+ var=
+ echo 0
0


Before I write a patch, is this bug documented? I could not find it in
the archives.

Is it a bug at all or is it expected behaviour?

According to the man page, it is not:

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 && or ⎪⎪ list, or if the command's return value is
being inverted via !

Andres P

Reply via email to