bug-bash
[Top][All Lists]
Advanced

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

Re: "unset var" pops var off variable stack instead of unsetting it


From: Chet Ramey
Subject: Re: "unset var" pops var off variable stack instead of unsetting it
Date: Sun, 19 Mar 2017 18:39:02 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:45.0) Gecko/20100101 Thunderbird/45.8.0

On 3/19/17 6:22 PM, Stephane Chazelas wrote:

>> $ cat x2
>> function foo
>> {
>> (
>>      unset -v IFS
>>      recho "${IFS-unset}"
>> )
>> }
>>
>> IFS=':|'
>> foo
>> echo after IFS = "$IFS"
>> $ ../bash-4.4-patched/bash ./x2
>> argv[1] = <unset>
>> after IFS = :|
> 
> Yes, that one is  fine but it is not the issue that is being
> discussed here. There's no variable to pop off a stack above.
> 
> the issue is when that "foo" function is called in a context
> where IFS had been declared locally. Like in:
> 
> IFS=1
> function example {
>   typeset IFS=2
>   foo
> }
> 
> Where "foo" would output "1", because then "unset -v IFS" would
> *not* have unset IFS but instead would have restored the value
> it had before the "typeset" (in that case, the global scope).
> 

Yeah, that's how local variables and dynamic scoping in bash have always
worked.  That ship really has sailed.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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