bug-bash
[Top][All Lists]
Advanced

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

Re: Stumped on a question of scoping and unset.


From: Freddy Vulto
Subject: Re: Stumped on a question of scoping and unset.
Date: Thu, 26 May 2011 09:44:31 +0200
User-agent: Mutt/1.5.20 (2009-06-14)

On 05:15, Steven W. Orr wrote:
> * Why is it needed to use the unset?
> * What does unset -v do extra for me?
> * What bad things could happen if I don't do the unset?

Upvars makes use of unset's capability of traversing down the
call-stack:

    a=0 b=0 c=0 d=0 e=0
    _unset() { unset -v b c c d d d e; }
    t1() {
        local a=1 b=1 c=1 d=1
        t2
    }
    t2() {
        local a=2 b=2 c=2 d=2 e=2
        _unset
        echo a:$a b:$b c:$c d:$d e:$e
    }
    t1  # Outputs: a:2 b:1 c:0 d: e:0
        #            ^   ^   ^   ^  ^-- unset once (skipped t1)
        #            |   |   |   +----- unset thrice to global
        #            |   |   +--------- unset twice till global
        #            |   +------------- unset once till t1
        #            +----------------- unset not

See also: http://fvue.nl/wiki/Bash:_Unset

Freddy Vulto
http://fvue.nl



reply via email to

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