bug-bash
[Top][All Lists]
Advanced

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

Re: 'local -x VARIABLE' does not clear variable for subprocesses


From: Chet Ramey
Subject: Re: 'local -x VARIABLE' does not clear variable for subprocesses
Date: Mon, 05 May 2014 11:18:50 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:24.0) Gecko/20100101 Thunderbird/24.5.0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 5/3/14, 7:22 PM, Arfrever Frehtes Taifersar Arahesis wrote:
> 'local -x VARIABLE' (without assignment of value) does not clear variable for 
> subprocesses.
> It is regression in bash 4.3.

It's not actually a regression; it's a bug fix.  It's worth having the
discussion again, though.

A variable isn't set until it's assigned a value.  A statement like
`local x' or `export x' doesn't actually create a variable.  It creates
a `placeholder' so that a subsequent assignment will instantiate a
variable with the right attributes, or change the behavior when a value
is assigned, but does not assign a value itself.  This means that
something like

export x
echo ${x-unset}
printenv x

will display `unset'.

The idea behind the bash-4.3 behavior is that the placeholder local
variable isn't set, and doesn't really exist.  It doesn't shadow a
global variable with the same name until it gets a value.  The bash-4.2
behavior was inconsistent: variables with attributes but without values
weren't quite set (value == 0x0, but still visible) and weren't quite
unset.  I tightened up the some of the consistency starting with bash-4.3
beta.  I'm sure there are still inconsistencies there (and, in fact, I
found one while looking at this).

If you want something that works in bash-4.2 and bash-4.3, assigning the
empty string to the local variables should get you most of the way where
you want to go.

Chet

- -- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iEYEARECAAYFAlNnq9oACgkQu1hp8GTqdKuE7ACgjHK7Pp3vdpKiD/KG3FS1/qtW
yiQAnRrpR4LB5X4ZQ7uALD4HvekSegvr
=5tgI
-----END PGP SIGNATURE-----



reply via email to

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