[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 16:12:54 -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/5/14, 1:13 PM, Arfrever Frehtes Taifersar Arahesis wrote:
> Behavior of bash 4.3 is inconsistent between non-subshell subprocesses and
> other places:
> bash 4.3.11:
>
> $ export VAR{1,2}=abc
> $ f() { local VAR1; local -x VAR2; echo "### Normal scope:"; declare -p
> VAR{1,2}; echo "### Subshell:"; (declare -p VAR{1,2}); echo "### Non-subshell
> subprocess:"; bash -c 'declare -p VAR{1,2}'; }
> $ f
> ### Normal scope:
> bash: declare: VAR1: not found
> bash: declare: VAR2: not found
> ### Subshell:
> bash: declare: VAR1: not found
> bash: declare: VAR2: not found
> ### Non-subshell subprocess:
> declare -x VAR1="abc"
> declare -x VAR2="abc"
A subshell is created as an exact copy of the parent shell, so the state
of local variables in the subshell is the same as in the parent, and I
would expect the behavior to be the same in both cases. You can argue
whether or not the behavior is correct -- I would argue that in this case
the behavior is incorrect.
A `non-subshell subprocess', as you've termed it, can only propagate
variables via the environment. So-called placeholder variables aren't
added to the environment.
I am thinking that as a general rule, variable lookups should not `find'
placeholder variables; assignments should. Implementing that general rule,
though, will take some close reading of the code.
> Ability to locally unset a variable also for subprocesses would be preferable
> solution.
OK. I'm not sure exactly what this means. Can you give me an example?
How would you use this in a situation where `unset' or `declare +x' are
unusable?
Chet
- --
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU chet@case.edu http://cnswww.cns.cwru.edu/~chet/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (Darwin)
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/
iEYEARECAAYFAlNn8MYACgkQu1hp8GTqdKsolQCfXBl+Rc7FtzIjLDYK5ck9UpRH
TXUAnRJABG8gky2z12y/RmE2HHWO7dvs
=/8oH
-----END PGP SIGNATURE-----