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

Ouch! unset '*'



In the course of playing around with the (lack of) local-ness of $argv, I
happened upon this bit of behavior:
----------
zsh% function ouch() { unset '*' }
zsh% set a b c
zsh% echo $*
a b c
zsh% ouch
zsh% echo $*

zsh% echo $@
a b c
----------

Once you get into this state, there's NO WAY to get $* to exist again, in
any scope.  At least with argv you can do `argv=($@)` to get it to exist
again (and to track $* properly too).  Similarly, `unset @` will kill $@
in all scopes for the duration of the current shell and its subshells.

Subsequent to `unset @` or `unset '*'` you can use `set ...` to get the
positional parameters back (so $1 $2 etc. work again), but this does not
restore any of $argv, $*, or $@ that have been individually unset.

This seems to me to be a pretty bad situation.  Worse, `unset -m '*'`
actually crashes 3.1.5-pws-7, though it does not crash 3.0.5.  It appears
that

zsh% unset PWD OLDPWD

is a minimum command necessary to cause this crash, though there may be
other combinations of variables that crash the shell when simultaneously
unset.  I haven't had a chance to investigate further, but `unset -m '*'`
ought to work.

Back on the original question, it seems to me that it shouldn't be possible
to unset '*' and '@', only to make them empty.  Is it sufficient to mark
them read-only, or will that prevent assigning to argv?
 

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com



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