From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: "Lawrence Velázquez" <vq@larryv.me>,
"Mikael Magnusson" <mikachu@gmail.com>
Cc: Bart Schaefer <schaefer@brasslantern.com>, zsh-workers@zsh.org
Subject: Re: bad math expression: illegal character: "
Date: Fri, 19 Jun 2020 16:55:13 +0100 (BST) [thread overview]
Message-ID: <599829801.251104.1592582113228@mail2.virginmedia.com> (raw)
In-Reply-To: <C7887F95-23FE-45E6-A1FF-0DF0996892AA@larryv.me>
> On 19 June 2020 at 07:38 Lawrence Velázquez <vq@larryv.me> wrote:
> 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
It's straightforward just to treat double quotes as if they're a
random spacing character. Not sure the error is actually useful?
There was a test for it but that was simply to make sure we did
something with them.
pws
diff --git a/Src/math.c b/Src/math.c
index 905b910ec..b57ba42d4 100644
--- a/Src/math.c
+++ b/Src/math.c
@@ -831,6 +831,8 @@ zzlex(void)
case ' ': /* Fall through! */
case '\t':
case '\n':
+ case '"': /* POSIX says ignore these */
+ case Dnull:
break;
default:
if (idigit(*--ptr) || *ptr == '.')
diff --git a/Test/C01arith.ztst b/Test/C01arith.ztst
index 419f45292..d0092fefa 100644
--- a/Test/C01arith.ztst
+++ b/Test/C01arith.ztst
@@ -180,9 +180,10 @@
1:bases beyond 36 don't work
?(eval):1: invalid base (must be 2 to 36 inclusive): 37
+ fail=39
print $(( 3 + "fail" ))
-1:parse failure in arithmetic
-?(eval):1: bad math expression: operand expected at `"fail" '
+0:Double quotes are not treated specially in arithmetic
+>42
alias 3=echo
print $(( 3 + "OK"); echo "Worked")
@@ -487,3 +488,8 @@
let noexist==0 )
1:Arithmetic, NO_UNSET part 3
?(eval):2: noexist: parameter not set
+
+ print $(( "6+2" / "1+3" ))
+0:Double quotes are not treated specially in arithmetic (POSIX)
+# and do not do grouping! this is 6 + (2/1) + 3
+>11
next prev parent reply other threads:[~2020-06-19 15:56 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
2020-06-19 15:55 ` Peter Stephenson [this message]
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=599829801.251104.1592582113228@mail2.virginmedia.com \
--to=p.w.stephenson@ntlworld.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).