From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8400 invoked by alias); 11 Mar 2011 20:53:13 -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: 28889 Received: (qmail 15685 invoked from network); 11 Mar 2011 20:53:11 -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, 11 Mar 2011 20:04:37 +0000 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: bug in ${##} expansion Message-ID: <20110311200437.18b5cad4@pws-pc.ntlworld.com> In-Reply-To: <4D7A72E8.5070909@redhat.com> References: <4D7A72E8.5070909@redhat.com> X-Mailer: Claws Mail 3.7.8 (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=JvdXmxIgLJv2/GthKqHpGJEEHukvLcvELVXUanXFreg= c=1 sm=0 a=kj9zAlcOel0A:10 a=20KFwNOVAAAA:8 a=NLZqzBF-AAAA:8 a=98iwYd6cbTI2cO-x058A:9 a=3Sq6Kf9-U0YM8LuGfakA:7 a=b_b5YKVynbJHQyIQdbx6CV9db88A:4 a=CjuIK1q_8ugA:10 a=jEp0ucaQiEUA:10 a=_dQi-Dcv4p4A:10 a=x0Y34NIWPWARwA3C:21 a=nwfgCCdQ0YSxav9U:21 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 On Fri, 11 Mar 2011 12:07:20 -0700 Eric Blake wrote: > POSIX requires ${#parameter} to expand to the length of parameter as a > string. It also requires that ${parameter#word} substitution have a > word (that is, ${parameter#} with a missing word is a zsh extension). > > Therefore, this should output 2, not 11: > > zsh -c 'set 1 2 3 4 5 6 7 8 9 10 11; echo ${##}' It's a straightforward bug, not specific to POSIX compatibility in this case; testing for a name after the # is a special case which covered some special names but not others. Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.117 diff -p -u -r1.117 subst.c --- Src/subst.c 11 Mar 2011 16:32:11 -0000 1.117 +++ Src/subst.c 11 Mar 2011 19:59:57 -0000 @@ -2039,6 +2039,7 @@ paramsubst(LinkList l, LinkNode n, char } else if ((c == '#' || c == Pound) && (itype_end(s+1, IIDENT, 0) != s + 1 || (cc = s[1]) == '*' || cc == Star || cc == '@' + || cc == '#' || cc == Pound || 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.54 diff -p -u -r1.54 D04parameter.ztst --- Test/D04parameter.ztst 18 Jan 2011 10:29:58 -0000 1.54 +++ Test/D04parameter.ztst 11 Mar 2011 19:59:57 -0000 @@ -175,6 +175,14 @@ 0:${#...}, $#... >8 8 8 8 8 8 8 8 + set 1 2 3 4 5 6 7 8 9 + print ${##} + set 1 2 3 4 5 6 7 8 9 10 + print ${##} +0:${##} is length of $# +>1 +>2 + array=(once bitten twice shy) print IF${array}THEN print IF${^array}THEN -- Peter Stephenson Web page now at http://homepage.ntlworld.com/p.w.stephenson/