From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5827 invoked by alias); 30 May 2015 23:30:40 -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: 35343 Received: (qmail 3211 invoked from network); 30 May 2015 23:30:37 -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=kj9zAlcOel0A:10 a=NLZqzBF-AAAA:8 a=q2GGsy2AAAAA:8 a=wQDBl6bHyPpB2SNs3YUA:9 a=oOoRCF3LikuJg_Y7:21 a=fDspeatWH1RnZLqv:21 a=CjuIK1q_8ugA:10 Date: Sun, 31 May 2015 00:30:34 +0100 From: Peter Stephenson To: Zsh hackers list Subject: Re: Arith parsing bug with minus after $# Message-ID: <20150531003034.45ae1d27@ntlworld.com> In-Reply-To: <150530152831.ZM17344@torch.brasslantern.com> References: <55676FB1.9080401@inlv.org> <20150529160237.6f329071@pwslap01u.europe.root.pri> <5568BF27.80806@inlv.org> <5423831432932500@web1o.yandex.ru> <20150530202412.2ff6de78@ntlworld.com> <20150530204046.0ae57c98@ntlworld.com> <150530152831.ZM17344@torch.brasslantern.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sat, 30 May 2015 15:28:31 -0700 Bart Schaefer wrote: > On May 30, 8:40pm, Peter Stephenson wrote: > } > } 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. > > POSIX_IDENTIFIERS, perhaps? That'll probably do. diff --git a/Doc/Zsh/expn.yo b/Doc/Zsh/expn.yo index afd6b1f..5a4be6b 100644 --- a/Doc/Zsh/expn.yo +++ b/Doc/Zsh/expn.yo @@ -777,6 +777,13 @@ This has the side-effect that joining is skipped even in quoted forms, which may affect other sub-expressions in var(spec). Note that `tt(^)', `tt(=)', and `tt(~)', below, must appear to the left of `tt(#)' when these forms are combined. + +If the option tt(POSIX_IDENTIFIERS) is not set, and var(spec) is a +simple name, then the braces are optional; this is true even +for special parameters so e.g. tt($#-) and tt($#*) take the length +of the string tt($-) and the array tt($*) respectively. If +tt(POSIX_IDENTIFIERS) is set, then braces are required for +the tt(#) to be treated in this fashion. ) item(tt(${^)var(spec)tt(}))( pindex(RC_EXPAND_PARAM, toggle) diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 4c0ae12..4dd68c9 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -2054,6 +2054,13 @@ When this option is set, only the ASCII characters tt(a) to tt(z), tt(A) to tt(Z), tt(0) to tt(9) and tt(_) may be used in identifiers (names of shell parameters and modules). +In addition, setting this option limits the effect of parameter +substitution with no braces, so that the expression tt($#) is treated as +the parameter tt($#) even if followed by a valid parameter name. +When it is unset, zsh allows expresions of the form tt($#)var(name) +to refer to the length of tt($)var(name), even for special variables, +for example in expressions such as tt($#-) and tt($#*). + When the option is unset and multibyte character support is enabled (i.e. it is compiled in and the option tt(MULTIBYTE) is set), then additionally any alphanumeric characters in the local character set may be used in diff --git a/Src/subst.c b/Src/subst.c index 168f7f1..81d34d2 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 = !(ifs && *ifs); } } else if ((c == '#' || c == Pound) && + (inbrace || !isset(POSIXIDENTIFIERS)) && (itype_end(s+1, IIDENT, 0) != s + 1 || (cc = s[1]) == '*' || cc == Star || cc == '@' || cc == '?' || cc == Quest @@ -2170,7 +2171,7 @@ paramsubst(LinkList l, LinkNode n, char **str, int qt, int pf_flags) */ || ((cc == '#' || cc == Pound) && s[2] == Outbrace) - || (inbrace && (cc == '-' || (cc == ':' && s[2] == '-'))) + || cc == '-' || (cc == ':' && s[2] == '-') || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) { getlen = 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 = ${~${(b)funnychars}} ]] 0:${(b)...} quoting protects from GLOB_SUBST - 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