Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
unset and locals
- X-seq: zsh-workers 1916
- From: "Bart Schaefer" <schaefer@xxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-workers@xxxxxxxxxxxxxxx
- Subject: unset and locals
- Date: Sun, 4 Aug 1996 01:07:35 -0700
- Reply-to: schaefer@xxxxxxx
This is so weird I'm having a hard time coming up with an example. Consider
these two functions:
one() {
local x=1
echo one $x before two
two
echo one $x after two
}
two() {
local x=2
echo two $x before unset
unset x
echo two $x after unset
unset x
echo two $x after repeat of unset
}
Executing "one" in zsh produces the output:
one 1 before two
two 2 before unset
two after unset
two after repeat of unset
one 1 after two
Now consider changing "two" as follows:
unlocal() {
unset $1
}
two() {
local x=2
echo two $x before unlocal
unlocal x
echo two $x after unlocal
unlocal x
echo two $x after repeat of unlocal
}
This produces the output:
one 1 before two
two 2 before unlocal
two 1 after unlocal
two after repeat of unlocal
one after two
Egad! By this strategem, "two" has succeeded in first unhiding (which is
good) and then unsetting (which in this instance is bad) a local variable
scoped in "one"!
Is there another way to "unhide" a variable from a higher scope? A way
that is guaranteed not to accidentally *unset* that same variable?
--
Bart Schaefer Brass Lantern Enterprises
http://www.well.com/user/barts http://www.nbn.com/people/lantern
New male in /home/schaefer:
>N 2 Justin William Schaefer Sat May 11 03:43 53/4040 "Happy Birthday"
Messages sorted by:
Reverse Date,
Date,
Thread,
Author