bug-bash
[Top][All Lists]
Advanced

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

Declaring variables as local effects command status $?


From: Michael Rendell
Subject: Declaring variables as local effects command status $?
Date: Fri, 6 Feb 2009 11:34:36 -0330
User-agent: KMail/1.9.3

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-redhat-linux-gnu' 
-DCONF_VENDOR='redhat' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' 
-DSHELL -DHAVE_CONFIG_H -DRECYCLES_PIDS   -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 nmhd-bs2 2.6.18-92.1.22.el5 #1 SMP Tue Dec 16 12:03:43 EST 
2008 i686 i686 i386 GNU/Linux
Machine Type: i686-redhat-linux-gnu

Bash Version: 3.2
Patch Level: 25
Release Status: release

Description:
        Declaring a variable as local appears to prevent $? from being set;
        see script below.

Repeat-By:
        script:

        #!/bin/sh
        testFunc() {
            local x=$( echo hi; exit 20);
            ret=$?
            echo "local var status: ret=($ret)"
            y=$( echo there; exit 21);
            ret=$?
            echo "non-local var status: ret=($ret)"
        }
        testFunc
        echo done...

        script output:
            local var status: ret=(0)
            non-local var status: ret=(21)
            done...






reply via email to

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