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

Re: Evaluation of $# - bug?



Bernd Eggink wrote:

> Hi,
> 
> for some reasons
> 
>     set a b c 
>     print $argv[$#-1]
> 
> prints nothing instead of "b", whereas both
> 
>     N=$#
>     print $argv[$N-1]
> 
> and
>     
>     print $argv[1,#-1]
> 
> work as expected. Can anybody explain this behaviour, or is it a bug? 
> It happens with 3.1.6 and 3.1.9-dev-7.

Always remember that there is a parameter named `-' (the option
string), so `$#-' gives the length of the value of that parameter and
`$#-1' gives that with a `1' stuck to the end.

Use `${#}-1'.


Bye
 Sven


--
Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx



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