bug-bash
[Top][All Lists]
Advanced

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

bash 3.2.51, ERR traps and subshells


From: Andres P
Subject: bash 3.2.51, ERR traps and subshells
Date: Tue, 22 Jun 2010 00:21:11 -0430

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

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