[pacman-dev] [[ and set -E vs trap ERR] - the [[ $( ! type workaround
Isaac Good
pacman at isaac.otherinbox.com
Thu Nov 19 22:08:04 EST 2009
Re: the bug with [[ $( type -p func ) ]] and the funky !
----- Forwarded message from Chet Ramey -----
Date: Thu, 19 Nov 2009 21:56:22 -0500
From: Chet Ramey
To: Isaac Good
Subject: Re: [[ and set -E vs trap ERR
Isaac Good wrote:
> 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
In bash-4.0, the conditional command does not honor the set -e option,
and as a result, doesn't pay attention to set -E either. The [[ and
(( commands will honor set -e in bash-4.1.
Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet at case.edu http://cnswww.cns.cwru.edu/~chet/
----- End forwarded message -----
More information about the pacman-dev
mailing list