Le 01/05/2010 09:18, Freddy Vulto a écrit :

> I would like to call t(), and let it return me a filled variable by
> reference, that is without polluting the global environment.

I'd like to know why you absolutely want the callee to perform a
side-effect on the caller. This is your original sin
IMHO. Side-effects are evil, use as little of them as you can. Here is
a more functional approach:

blackbox() {
    local a
    printf '%s\n' "$1=bar1"
    printf '%s\n' "$2=bar2"
}
f() {
    local b c
    # This eval is safe because we trust our own, simple blackbox
    # function
    eval $(blackbox b c)
    echo $b; echo $c
}


Of course whenever "blackbox" returns only one value the whole thing
can be much simpler, just: b=$(blackbox)






Reply via email to