zsh-workers
 help / color / mirror / code / Atom feed
From: ZyX <kp-pav@yandex.ru>
To: Martijn Dekker <martijn@inlv.org>,
	"zsh-workers@zsh.org" <zsh-workers@zsh.org>
Subject: Re: Arith parsing bug with minus after $#
Date: Fri, 29 May 2015 23:48:20 +0300	[thread overview]
Message-ID: <5423831432932500@web1o.yandex.ru> (raw)
In-Reply-To: <5568BF27.80806@inlv.org>



29.05.2015, 22:34, "Martijn Dekker" <martijn@inlv.org>:
> Bart Schaefer schreef op 29-05-15 om 20:09:
>>  On May 29, 2015 8:02 AM, "Peter Stephenson" <p.stephenson@samsung.com>
>>  wrote:
>>>  The problem is the overloading of "#" --- the test to establish what to
>>>  do with it is trying too hard to resolve to ${#-}, which is a valid
>>>  substitution, because it hasn't taken into account that there are no
>>>  braces.  So what you're seeing is ${#-}1.
>>  I think this actually was discussed on austin-group a few months back.  My
>>  recollection is that zsh's behavior was deemed permissible and I therefore
>>  thought no more about it at the time.
>
> It is incompatible with every other shell and with the POSIX spec.
> Parameter expansion is only supposed to be done if braces are present. See:
> http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

It says that they are optional:

> The parameter name or symbol can be enclosed in braces, which are optional except for positional parameters with more than one digit or when parameter is a name and is followed by a character that could be interpreted as part of the name. The matching closing brace shall be determined by counting brace levels, skipping over enclosed quoted strings, and command substitutions.

This is the fourth paragraph.

But later it explicitly says that not enclosed in single braces may only be names or single-character variables. I.e. $#- is ${#}-, $10 is ${1}0, …

Besides $#- zsh has things like $array[index]: needs not be enclosed in braces (depends on some option: in `emulate sh` or `emulate ksh` this is ${array}[index], same in ksh). Or $file:h. I guess there are more I do not know about.

>
> - M.


  reply	other threads:[~2015-05-29 20:54 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-28 19:42 Martijn Dekker
2015-05-29 15:02 ` Peter Stephenson
2015-05-29 15:43   ` Martijn Dekker
2015-05-29 18:09   ` Bart Schaefer
2015-05-29 19:33     ` Martijn Dekker
2015-05-29 20:48       ` ZyX [this message]
2015-05-29 21:24         ` Bart Schaefer
2015-05-30 19:24           ` Peter Stephenson
2015-05-30 19:40             ` Peter Stephenson
2015-05-30 22:28               ` Bart Schaefer
2015-05-30 23:30                 ` Peter Stephenson
2015-06-07  1:08   ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5423831432932500@web1o.yandex.ru \
    --to=kp-pav@yandex.ru \
    --cc=martijn@inlv.org \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).