(set -u -e; trap true EXIT; echo $bad) exits 0
Configuration Information [Automatically generated, do not change]: Machine: i486 OS: linux-gnu Compiler: gcc Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include -I../bash/lib -g -O2 -Wall uname output: Linux pzlaptop 2.6.22-gg15-generic #1 SMP Fri Sep 26 12:50:35 EST 2008 i686 GNU/Linux Machine Type: i486-pc-linux-gnu Bash Version: 3.2 Patch Level: 25 Release Status: release Description: The following command $ (set -u -e; trap true EXIT; echo $bad;) && echo OK displays bash: bad: unbound variable OK I'd think it should exits with a non-zero error code and not display OK. This is exacly what happens if you remove -e. I'm not sure whether this is of any use, but in the outputs below, we have '++ true' in the first case, and '+ true' in the other. $ (set -x -u -e; trap true EXIT; echo $bad;) + trap true EXIT bash: bad: unbound variable ++ true $ (set -x -u; trap true EXIT; echo $bad;) + trap true EXIT bash: bad: unbound variable + true Repeat-By: Execute the above command.
Re: (set -u -e; trap true EXIT; echo $bad) exits 0
2009/4/11 Chet Ramey : > Piotr Zielinski wrote: >> Configuration Information [Automatically generated, do not change]: >> Machine: i486 >> OS: linux-gnu >> Compiler: gcc >> Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i486' >> -DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i486-pc-linux-gnu' >> -DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' >> -DSHELL -DHAVE_CONFIG_H -I. -I../bash -I../bash/include >> -I../bash/lib -g -O2 -Wall >> uname output: Linux pzlaptop 2.6.22-gg15-generic #1 SMP Fri Sep 26 >> 12:50:35 EST 2008 i686 GNU/Linux >> Machine Type: i486-pc-linux-gnu >> >> Bash Version: 3.2 >> Patch Level: 25 >> Release Status: release >> >> Description: >> The following command >> >> $ (set -u -e; trap true EXIT; echo $bad;) && echo OK >> >> displays >> >> bash: bad: unbound variable >> OK >> >> I'd think it should exits with a non-zero error code and not >> display OK. This is exacly what happens if you remove -e. > > Thanks for the report. The problem is that bash doesn't always set > $? before testing whether or not the shell should exit because -e has > been set and an unset variable is being expanded. Thanks for the reply. Does it mean it is a bug or a feature? Piotr > Chet > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > > Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/ >