* bug in ${##} expansion @ 2011-03-11 19:07 Eric Blake 2011-03-11 20:04 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Eric Blake @ 2011-03-11 19:07 UTC (permalink / raw) To: zsh-workers [-- Attachment #1: Type: text/plain, Size: 420 bytes --] 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 ${##}' -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org [-- Attachment #2: OpenPGP digital signature --] [-- Type: application/pgp-signature, Size: 619 bytes --] ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in ${##} expansion 2011-03-11 19:07 bug in ${##} expansion Eric Blake @ 2011-03-11 20:04 ` Peter Stephenson 2011-03-21 10:15 ` Peter Stephenson 0 siblings, 1 reply; 3+ messages in thread From: Peter Stephenson @ 2011-03-11 20:04 UTC (permalink / raw) To: zsh-workers On Fri, 11 Mar 2011 12:07:20 -0700 Eric Blake <eblake@redhat.com> 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 <p.w.stephenson@ntlworld.com> Web page now at http://homepage.ntlworld.com/p.w.stephenson/ ^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: bug in ${##} expansion 2011-03-11 20:04 ` Peter Stephenson @ 2011-03-21 10:15 ` Peter Stephenson 0 siblings, 0 replies; 3+ messages in thread From: Peter Stephenson @ 2011-03-21 10:15 UTC (permalink / raw) To: zsh-workers On Fri, 11 Mar 2011 20:04:37 +0000 Peter Stephenson <p.w.stephenson@ntlworld.com> wrote: > On Fri, 11 Mar 2011 12:07:20 -0700 > Eric Blake <eblake@redhat.com> 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. A couple more missing. Index: Src/subst.c =================================================================== RCS file: /cvsroot/zsh/zsh/Src/subst.c,v retrieving revision 1.118 diff -p -u -r1.118 subst.c --- Src/subst.c 11 Mar 2011 21:06:00 -0000 1.118 +++ Src/subst.c 21 Mar 2011 10:13:00 -0000 @@ -2039,6 +2039,8 @@ 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 == Quest + || cc == '$' || cc == String || cc == Qstring || cc == '#' || cc == Pound || cc == '-' || (cc == ':' && s[2] == '-') || (isstring(cc) && (s[2] == Inbrace || s[2] == Inpar)))) { -- Peter Stephenson <pws@csr.com> Software Engineer Tel: +44 (0)1223 692070 Cambridge Silicon Radio Limited Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2011-03-21 11:06 UTC | newest] Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2011-03-11 19:07 bug in ${##} expansion Eric Blake 2011-03-11 20:04 ` Peter Stephenson 2011-03-21 10:15 ` Peter Stephenson
Code repositories for project(s) associated with this public inbox https://git.vuxu.org/mirror/zsh/ This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).