* Re: Evaluation of $# - bug?
[not found] <200012041133.MAA05780@beta.informatik.hu-berlin.de>
@ 2000-12-04 11:57 ` Peter Stephenson
2000-12-04 16:04 ` Bart Schaefer
0 siblings, 1 reply; 2+ messages in thread
From: Peter Stephenson @ 2000-12-04 11:57 UTC (permalink / raw)
To: Zsh hackers list
> 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@csr.com> Software Engineer
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
^ permalink raw reply [flat|nested] 2+ messages in thread