From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8207 invoked by alias); 3 Jun 2011 20:43:09 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 29451 Received: (qmail 20001 invoked from network); 3 Jun 2011 20:42:57 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received-SPF: pass (ns1.primenet.com.au: SPF record at ntlworld.com designates 81.103.221.56 as permitted sender) Date: Fri, 3 Jun 2011 21:16:23 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: regression in ${##""} Message-ID: <20110603211623.79e653c6@pws-pc.ntlworld.com> In-Reply-To: References: <4DE9212A.2080601@redhat.com> X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=R50lirqlHffDPPkwUlkuVa99MrvKdVWo//yz83qex8g= c=1 sm=0 a=zrZUpIq7OtkA:10 a=uObrxnre4hsA:10 a=kj9zAlcOel0A:10 a=pGLkceISAAAA:8 a=NLZqzBF-AAAA:8 a=TzhyVtqvm1dwCgGc2G0A:9 a=B9t8r8nSVX99Mo1kPicA:7 a=CjuIK1q_8ugA:10 a=MSl-tDqOz04A:10 a=_dQi-Dcv4p4A:10 a=ZKPXbgTXKiitVJzR:21 a=PLMWFRVlOpbJSkht:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Fri, 3 Jun 2011 20:55:00 +0200 Mikael Magnusson 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 Web page now at http://homepage.ntlworld.com/p.w.stephenson/