bug-bash
[Top][All Lists]
Advanced

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

undo local variable with unset


From: Poor Yorick
Subject: undo local variable with unset
Date: Mon, 05 Jan 2015 13:14:53 -0700
User-agent: Roundcube Webmail/1.0.2

In the following script, the effect of calling f0 is that the value global $i is still 5, but the effect of calling f1 is that the value of the global $i is 9. It's nice to be able to create a function like unlocal that moves local variables out of the way, but I'm wondering if it can be relied on in future
versions:

    unlocal () {
        unset -v "$@"
    }

    f0 () {
     local i
     i=3
     unset -v i
     f1
     i=9
    }

    f1 () {
        local i
        i=3
        unlocal i
        i=9
    }

    i=5


--
Yorick




reply via email to

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