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

Re: regression in ${##""}



On Fri, 3 Jun 2011 20:55:00 +0200
Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> > $ ./Src/zsh -c 'set a b; echo ${##""}'
> > zsh:1: bad substitution
> 
> Not a surprise, this is due to
> 
> 28889: ${##} should return the length of $#

Indeed.  How not to define a language, lesson 1:  make the same
symbol have three different meanings in a single expression.

I confess that zsh's own parameter syntax is actually starting to look
rather more attractive... just not very.

Index: Src/subst.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/subst.c,v
retrieving revision 1.124
diff -p -u -r1.124 subst.c
--- Src/subst.c	23 May 2011 16:08:47 -0000	1.124
+++ Src/subst.c	3 Jun 2011 20:13:21 -0000
@@ -2080,7 +2080,16 @@ paramsubst(LinkList l, LinkNode n, char 
 		    || (cc = s[1]) == '*' || cc == Star || cc == '@'
 		    || cc == '?' || cc == Quest
 		    || cc == '$' || cc == String || cc == Qstring
-		    || cc == '#' || cc == Pound
+		    /*
+		     * Me And My Squiggle:
+		     * ${##} is the length of $#, but ${##foo}
+		     * is $# with a "foo" removed from the start.
+		     * If someone had defined the *@!@! language
+		     * properly in the first place we wouldn't
+		     * have this nonsense.
+		     */
+		    || ((cc == '#' || cc == Pound) &&
+			s[2] == Outbrace)
 		    || cc == '-' || (cc == ':' && s[2] == '-')
 		    || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) {
 	    getlen = 1 + whichlen, s++;
Index: Test/D04parameter.ztst
===================================================================
RCS file: /cvsroot/zsh/zsh/Test/D04parameter.ztst,v
retrieving revision 1.57
diff -p -u -r1.57 D04parameter.ztst
--- Test/D04parameter.ztst	19 May 2011 16:24:38 -0000	1.57
+++ Test/D04parameter.ztst	3 Jun 2011 20:13:21 -0000
@@ -179,9 +179,17 @@
   print ${##}
   set 1 2 3 4 5 6 7 8 9 10
   print ${##}
-0:${##} is length of $#
+  print ${##""}
+  print ${##1}
+  print ${##2}
+  print ${###<->} # oh, for pete's sake...
+0:${##} is length of $#, and other tales of hash horror
 >1
 >2
+>10
+>0
+>10
+>
 
   array=(once bitten twice shy)
   print IF${array}THEN


-- 
Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/



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