Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Global And Local Variables in zsh Functions



On Aug 9, 12:44am, Georg Wittig wrote:
}
} x1=$(my_f2 /tmp)
} x2=$(my_f2 /opt/windows7)
} 
} To my surprise, EXC is empty now:
} 
} Why is EXC empty in the case of my_f2, and correct in the case my_f1?

The use of $(...) means your my_f2 function runs in a forked child process,
and so changes to variables are not visible to the parent shell.  If you
want my_f2 to work like my_f1, you'll have to do something like

function my_f2 () {
    EXC+=" --exclude='$1'";
    typeset -g $2="some value depending on $1"
}

my_f2 /tmp x1
my_f2 /opt/windows7 x2



Messages sorted by: Reverse Date, Date, Thread, Author