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

Re: parameter substitution used in _values



On Jun 1,  3:39pm, Sven Wischnowsky wrote:
} Subject: Re: parameter substitution used in _values
}
} The problem is that the positional parameters are internally turned into
} `$argv[n]'.

This is a bit strange on many levels:

zsh% noargv() { unset argv }
zsh% showargv() {
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> noargv
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> unset argv
function> echo 1=$1 2=$2 @=\($@\) argv=\($argv\) $+argv
function> }
zsh% showargv a b c d
1=a 2=b @=(a b c d) argv=(a b c d) 1
1=a 2=b @=(a b c d) argv=() 0
1= 2= @=() argv=() 0

So `unset argv' somehow did something with a param that was already unset.
Now run `showargv' a second time in the same shell:

zsh% showargv d c b a
1=d 2=c @=(d c b a) argv=() 0
1=d 2=c @=(d c b a) argv=() 0
1= 2= @=() argv=() 0

This is sort of documented:

argv <S> <Z>
     Same as *.  Assigning to argv changes the local positional
     parameters, but argv is *not* itself a local parameter.  Deleting
     argv with unset in any function deletes it everywhere, although
     only the innermost positional parameter array is deleted (so * and
     @ in other scopes are not affected).

It seems a bit odd that `unset argv' continues to have side effects after
argv has already been "deleted" but I guess that's just part of it being
<S>pecial.

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

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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