On 5/4/10 1:57 PM, Freddy Vulto wrote:
> It appears that `unset' is capable of traversing down the call-stack and
> unsetting variables repeatedly:
> 
>     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
> 
> It seems to work on bash-3.0, 3.2, 4.0 and 4.1.
> Is this a bug or a feature?

It's not a bug.  A feature is what you make of it.  Consider that unset
processes its arguments beginning to end, so the above function body
could equivalently be written as a series of unset commands:

unset -v b
unset -v c
unset -v c
unset -v d
        ...and so on...

Then think about the state of the bash variable contexts after each
command.

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


Reply via email to