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

Re: Evaluation of $# - bug?



> 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'.

This probably deserves a special note.  Unless anybody really objects to
clarity in the documentation.

Index: Doc/Zsh/params.yo
===================================================================
RCS file: /cvsroot/zsh/zsh/Doc/Zsh/params.yo,v
retrieving revision 1.5
diff -u -r1.5 params.yo
--- Doc/Zsh/params.yo	2000/08/29 06:35:40	1.5
+++ Doc/Zsh/params.yo	2000/12/04 11:55:35
@@ -240,7 +240,11 @@
 )
 vindex(#)
 item(tt(#) <S>)(
-The number of positional parameters in decimal.
+The number of positional parameters in decimal.  Note that some confusion
+may occur with the syntax tt($#)var(param) which substitutes the length of
+var(param).  Use tt(${#}) to resolve ambiguities.  In particular, the
+sequence `tt($#-)var(...)' in an arithmetic expression is interpreted as
+the length of the parameter tt(-), q.v.
 )
 vindex(ARGC)
 item(tt(ARGC) <S> <Z>)(

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK                          Tel: +44 (0)1223 392070



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