bug-bash
[Top][All Lists]
Advanced

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

[[ and set -E vs trap ERR


From: Isaac Good
Subject: [[ and set -E vs trap ERR
Date: Mon, 16 Nov 2009 20:01:03 -0500
User-agent: Mutt/1.5.20 (2009-06-14)

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='i686' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i686-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -         DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H   -I.  -I. -I./include -I./lib   -march=i686 
-mtune=generic -O2 -pipe
uname output: Linux arch 2.6.31-ARCH #1 SMP PREEMPT Fri Oct 23 11:12:58 CEST 
2009 i686 Pentium III (Katmai) GenuineIntel GNU/Linux
Machine Type: i686-pc-linux-gnu

Bash Version: 4.0
Patch Level: 35
Release Status: release

cat <<-EOF >test
        #!/bin/bash -e
        set -E
        trap 'echo >&2 "error"' ERR

        echo TEST1
        if [ $(false) ] ; then
                        echo 1
        fi

        echo TEST2
        if [[ $(false) ]] ; then
                        echo 1
        fi
EOF

Expected output:
TEST1
TEST2

Actual output:
TEST1
TEST2
error

The [[ masks the fact that an 'if' is running - but only in regards to the 
trap. bash does not exit on this error but the trap is triggered. 
[ works fine.
With set -E, the trap is inherited by command substitution, but the fact that 
the trap is suppressed is not.

<\amethyst> but the manpage says the ERR trap is avoided under "the same 
conditions obeyed by the errexit option", so at least the documentation is in 
error if nothing else




reply via email to

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