[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Declaring a local variable circumvents "-e"
From: |
Björn Augustsson |
Subject: |
Declaring a local variable circumvents "-e" |
Date: |
Wed, 24 Sep 2008 21:01:57 +0200 |
Configuration Information [Automatically generated, do not change]:
Machine: i386
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -DPROGRAM='bash' -DCONF_HOSTTYPE='i386'
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='i386-redhat-linux-gnu'
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale'
-DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H -I. -I. -I./include
-I./lib -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -O2
-g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector
--param=ssp-buffer-size=4 -m32 -march=i386 -mtune=generic
-fasynchronous-unwind-tables
uname output: Linux blahonga 2.6.25.14-69.fc8 #1 SMP Mon Aug 4
14:20:24 EDT 2008 i686 i686 i386 GNU/Linux
Machine Type: i386-redhat-linux-gnu
Bash Version: 3.2
Patch Level: 33
Release Status: release
Description:
The test case below is pretty self-explanatory.
The assignment in fun_bad() doesn't exit the shell,
despite the "set -e".
This is the version in Fedora 8.
Also happens on
* Bash Version: 3.1 Patch Level: 17 (Ubuntu Dapper)
* Bash Version: 3.2 Patch Level: 0 (from ftp.gnu.org))
Repeat-By:
-----------------------------8<-------------------------
#!/bin/bash
set -e
fun_bad() {
local bah=$( false )
}
fun_good() {
local bah
bah=$( false )
}
echo "start"
fun_bad
echo "FAIL"
fun_good
echo "(Does not get here.)"
-----------------------------8<-------------------------
Fix:
I haven't written a fix.
A workaround is detailed in the test case. In short, if you declare
variable on one line, and assign it on the next, it works as expected.
/August.
- Declaring a local variable circumvents "-e",
Björn Augustsson <=