FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 11-20-2009, 02:08 AM
Isaac Good
 
Default - the [[ $( ! type workaround

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@case.edu http://cnswww.cns.cwru.edu/~chet/

----- End forwarded message -----
 

Thread Tools




All times are GMT. The time now is 08:35 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org