bug-bash
[Top][All Lists]
Advanced

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

new local variables might be unset or set to ''


From: neil
Subject: new local variables might be unset or set to ''
Date: Thu, 11 Sep 2008 11:49:53 -0400

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 dirac.s-z.org 2.6.24-1-686 #1 SMP Mon Feb 11 14:37:45 UTC 
2008 i686 GNU/Linux
Machine Type: i486-pc-linux-gnu

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

Description:
        'local var' toggles the 'set'-ness of var unless it was already
        local.  That is, if the old variable was set (local or not), or
        if it was an unset local variable in a different context, the new
        local variable will be unset.  However, if no variable by that
        name was present, the new local variable will be set to the empty
        string.  The correct behaviour is not clearly documented, but
        it would be more parsimonious to always unset the variable.
        This is the approach taken by ksh93:
           function foo { typeset var; echo ${var-undefined}; }
        will always print 'undefined' in that shell.

Repeat-By:
        foo () { local opt; echo "${opt-undefined in foo}"; }
        bar() { local opt; echo "${opt-undefined in bar}"; foo; }

        unset opt; bar   # prints "undefined in foo" (but not bar)
        opt=xyzzy; bar   # prints "undefined in bar" and "undefined in foo"


Fix:
        The following patch makes the new variable always undefined.

        Other options would be to always bind the new variable to the empty
        string; or to use the value and state of the old variable.

--- variables.c.orig    2008-09-11 11:31:11.833318420 -0400
+++ variables.c 2008-09-11 11:31:45.545668777 -0400
@@ -1689,7 +1689,7 @@
     }
 
   if (old_var == 0)
-    new_var = bind_variable_internal (name, "", vc->table, HASH_NOSRCH, 0);
+    new_var = make_new_variable (name, vc->table);
   else
     {
       new_var = make_new_variable (name, vc->table);




reply via email to

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