From: Sebastian Gniazdowski <sgniazdowski@gmail.com>
To: "Lawrence Velázquez" <vq@larryv.me>
Cc: Mikael Magnusson <mikachu@gmail.com>,
Bart Schaefer <schaefer@brasslantern.com>,
Zsh hackers list <zsh-workers@zsh.org>
Subject: Re: bad math expression: illegal character: "
Date: Fri, 19 Jun 2020 17:35:25 +0200 [thread overview]
Message-ID: <CAKc7PVByzrhZ2ezkBO-CFdasnXdDPbNOiG6NmdXhOu=EX1uLHA@mail.gmail.com> (raw)
In-Reply-To: <C7887F95-23FE-45E6-A1FF-0DF0996892AA@larryv.me>
[-- Attachment #1: Type: text/plain, Size: 2662 bytes --]
Maybe a bash emulation could be added? Equal to:
emulate zsh -o noshglob -o braceexpand -o kshglob
+ the quotes inside (( ))? emulate already accepts "bash" as the emulation
level.
On Fri, 19 Jun 2020 at 08:39, Lawrence Velázquez <vq@larryv.me> wrote:
> > On Jun 18, 2020, at 7:19 AM, Mikael Magnusson <mikachu@gmail.com> wrote:
> >
> >> On 6/18/20, Bart Schaefer <schaefer@brasslantern.com> wrote:
> >>
> >>> On Fri, Jun 5, 2020 at 2:02 PM Lawrence Velázquez <vq@larryv.me>
> wrote:
> >>>
> >>>> On Jun 5, 2020, at 2:18 PM, Artur Renault <
> Artur.Renault@microsoft.com>
> >>>>
> >>>> while (( "$#" )); do
> >>>>
> >>>> repro.sh:1: bad math expression: illegal character: "
> >>>
> >>> For what it's worth, dash also rejects this. I assume that it and
> >>> zsh are just more strict about what constitutes a math expression.
> >>
> >> Does anybody know if this is something we should change for sh
> >> emulation, or is it merely another unspecified POSIX corner-case?
> >
> > If this is a POSIX requirement, it must have been very specific about
> > when quotes should be allowed (bash):
> >
> > $ (( "0" )); echo $?
> > 1
> > $ echo $(( "0" ))
> > bash: "0" : syntax error: operand expected (error token is ""0" ")
>
> Looks like the bash behavior changed at some point?
>
> % /bin/bash --version | head -n 1
> GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin18)
> % /bin/bash -c '(( "0" )); echo $?'
> 1
> % /bin/bash -c 'echo $(( "0" ))'
> /bin/bash: "0" : syntax error: operand expected (error token is ""0" ")
>
> % /opt/local/bin/bash --version | head -n 1
> GNU bash, version 5.0.17(1)-release (x86_64-apple-darwin18.7.0)
> % /opt/local/bin/bash -c '(( "0" )); echo $?'
> 1
> % /opt/local/bin/bash -c 'echo $(( "0" ))'
> 0
>
> Anyway, unless I'm missing something, POSIX seems pretty clear about
> this, as far as $((...)) goes:
>
> The expression shall be treated as if it were in double-quotes,
> except that a double-quote inside the expression is not treated
> specially. The shell shall expand all tokens in the expression
> for parameter expansion, command substitution, and **quote
> removal**. [Emphasis mine.]
>
> Next, the shell shall treat this as an arithmetic expression
> and substitute the value of the expression.
>
>
> https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_04
>
> vq
--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zinit
Blog: http://zdharma.org
next prev parent reply other threads:[~2020-06-19 15:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-05 18:18 Artur Renault
2020-06-05 21:01 ` Lawrence Velázquez
2020-06-17 23:21 ` Bart Schaefer
2020-06-18 11:19 ` Mikael Magnusson
2020-06-19 6:38 ` Lawrence Velázquez
2020-06-19 15:35 ` Sebastian Gniazdowski [this message]
2020-06-19 15:55 ` Peter Stephenson
2020-06-22 11:11 ` Peter Stephenson
2020-06-23 23:51 ` 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='CAKc7PVByzrhZ2ezkBO-CFdasnXdDPbNOiG6NmdXhOu=EX1uLHA@mail.gmail.com' \
--to=sgniazdowski@gmail.com \
--cc=mikachu@gmail.com \
--cc=schaefer@brasslantern.com \
--cc=vq@larryv.me \
--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).