Re: "unset var" pops var off variable stack instead of unsetting it
From:
Stephane Chazelas
Subject:
Re: "unset var" pops var off variable stack instead of unsetting it
Date:
Tue, 21 Mar 2017 15:38:55 +0000
User-agent:
Mutt/1.5.24 (2015-08-30)
2017-03-20 16:32:10 -0400, Chet Ramey:
[...]
> > See also:
> >
> > $ bash -c 'f() { unset a; echo "$a";}; a=1; a=2 f'
> > 1
> >
> > already mentioned.
>
> A distinction without a difference; the behavior is explicitly the same.
[...]
One I haven't mentioned yet is:
$ bash -c 'f() { local a; unset a; echo "$a";}; a=1; a=2 f'
1
IOW, the work around I was mentioning earlier (of using "local"
before "unset" to make sure "unset" unsets) doesn't work in that
case. You'd need to use the same work around as for mksh/yash
(call unset in a loop until the variable is really unset (with
the nasty side effect of unsetting the variable in a scope
you're need meant to tamper with) so you'd want to do it in a
subshell).
--
Stephane