From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16765 invoked by alias); 30 May 2015 19:40:51 -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: 35341 Received: (qmail 14892 invoked from network); 30 May 2015 19:40:49 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) 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, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=TYVrzkkh c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=IkcTkHD0fZMA:10 a=NLZqzBF-AAAA:8 a=q2GGsy2AAAAA:8 a=vaJtXVxTAAAA:8 a=nCte7c_NU4UNmW3Ff3UA:9 a=v3Ad1NFMBxCNOwoY:21 a=mSiDY8ojti9eryMk:21 a=QEXdDO2ut3YA:10 Date: Sat, 30 May 2015 20:40:46 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: Arith parsing bug with minus after $# Message-ID: <20150530204046.0ae57c98@ntlworld.com> In-Reply-To: <20150530202412.2ff6de78@ntlworld.com> References: <55676FB1.9080401@inlv.org> <20150529160237.6f329071@pwslap01u.europe.root.pri> <5568BF27.80806@inlv.org> <5423831432932500@web1o.yandex.ru> <20150530202412.2ff6de78@ntlworld.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sat, 30 May 2015 20:24:12 +0100 Peter Stephenson wrote: > On Fri, 29 May 2015 14:24:45 -0700 > Bart Schaefer wrote: > > On May 29, 2015 1:54 PM, "ZyX" wrote: > > > > > > But later it explicitly says that not enclosed in single braces may o= nly > > be names or single-character variables. I.e. $#- is ${#}-, $10 is ${1}0= , =E2=80=A6 > >=20 > > Yes, but $#name to return the length of the value of $name is already a= zsh > > extension, so unless we're in some emulation mode, treating $#- as the > > length of $- is perfectly reasonable. >=20 > Perhaps more interesting is $#*, since "*" is a much more commmon > special parameter that's also an operator, and isn't quite so horrifically > overloaded in parameter substitution. >=20 > % emulate sh -c 'fn() { echo $(( $#*3 )); }' > % fn one > 13 >=20 > That looks like it needs some emulation, though it can wait since nobody's > tripped over it. It's easy, though, so no time like the present... and this ought to be consistent across all parameters, so make "-" behave the same. What I'm not sure about is how to decide. SH_WORD_SPLIT isn't the same thing, though there's an obvious mnemonic for why it might have this effect. We have the option of basing it on emulation alone, but that always strikes me as something of a counsel of despair. I'll add documentation when this gets decided. diff --git a/Src/subst.c b/Src/subst.c index 168f7f1..67bd088 100644 --- a/Src/subst.c +++ b/Src/subst.c @@ -2156,6 +2156,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt= , int pf_flags) nojoin =3D !(ifs && *ifs); } } else if ((c =3D=3D '#' || c =3D=3D Pound) && + (inbrace || !isset(SHWORDSPLIT)) && (itype_end(s+1, IIDENT, 0) !=3D s + 1 || (cc =3D s[1]) =3D=3D '*' || cc =3D=3D Star || cc =3D=3D '@' || cc =3D=3D '?' || cc =3D=3D Quest @@ -2170,7 +2171,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt= , int pf_flags) */ || ((cc =3D=3D '#' || cc =3D=3D Pound) && s[2] =3D=3D Outbrace) - || (inbrace && (cc =3D=3D '-' || (cc =3D=3D ':' && s[2] =3D=3D '-'))) + || cc =3D=3D '-' || (cc =3D=3D ':' && s[2] =3D=3D '-') || (isstring(cc) && (s[2] =3D=3D Inbrace || s[2] =3D=3D Inpar)))) { getlen =3D 1 + whichlen, s++; /* diff --git a/Test/D04parameter.ztst b/Test/D04parameter.ztst index c41e05e..d06a73a 100644 --- a/Test/D04parameter.ztst +++ b/Test/D04parameter.ztst @@ -1704,7 +1704,10 @@ [[ $funnychars =3D ${~${(b)funnychars}} ]] 0:${(b)...} quoting protects from GLOB_SUBST =20 - set -- - print $#-1 -0:Avoid confusion after overloaded characters in braceless substitution + set -- foo + echo $(( $#*3 )) + emulate sh -c 'nolenwithoutbrace() { echo $#-1; }' + nolenwithoutbrace +0:Avoid confusion after overloaded characters in braceless substitution in= sh +>13 >0-1