From: Michael Greenberg <Michael.Greenberg@pomona.edu>
To: Martijn Dekker <martijn@inlv.org>
Cc: "dash@vger.kernel.org" <dash@vger.kernel.org>,
Austin John Blatt <ajb22014@MyMail.pomona.edu>
Subject: Re: [PATCH] unset/null variables should expand to 0 during arithmetic expansion
Date: Wed, 1 Feb 2017 18:28:52 +0000 [thread overview]
Message-ID: <83950DC1-1C85-4C0C-804D-FD795F6EA558@pomona.edu> (raw)
In-Reply-To: <cc2914b7-c2f3-82a0-3b2a-6e4885c5f34f@inlv.org>
Hi Martijn,
> On Jan 29, 2017, at 4:13 PM, Martijn Dekker <martijn@inlv.org> wrote:
>
> Op 19-01-17 om 21:06 schreef Michael Greenberg:
>> unset x ; echo $((x+=2))
>>
>> Running bash on this program echoes the number 2 to standard out and sets x to 2. Running dash (git HEAD/release 0.5.9.1) yields an error:
>>
>> src/dash: 1: Illegal number:
>
> Yes, looks like a dash-specific bug. The related shells Busybox ash and
> FreeBSD /bin/sh act like POSIX says they should.
Great! Please pardon my naivete, but is there anything else I can or should do to see that this bug patch gets accepted and applied?
>> The standard is a little bit unclear about what to do for variables that are set to null (or non-numeric values). I’d interpret the standard as defaulting for unset variables, having null and other non-numeric strings cause some kind of error. bash, as usual, goes well beyond what the standard indicates: any non-numerical value is defaulted to 0. So:
>>
>> x="" ; echo $((x+=2))
>>
>> x=“yo” ; echo $((x+=2))
>>
>> both yield 2! If you ask me, that’s a bridge too far—and asking for bugs.
>
> That's recursive arithmetic expression parsing in bash, ksh and zsh; if
> the value of a variable is an arithmetic expression (including simply
> another variable name, such as "yo") this is evaluated, which in this
> case means the value of "x" is taken as the value of "yo" which is taken
> as zero. That behaviour is not specified by POSIX, of course.
Right. I only mentioned it because I—as I think we both agree—this behavior is underspecified and probably good as-is. :)
Cheers,
Michael
prev parent reply other threads:[~2017-02-01 18:28 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-19 21:06 [PATCH] unset/null variables should expand to 0 during arithmetic expansion Michael Greenberg
2017-01-30 0:13 ` Martijn Dekker
2017-02-01 18:28 ` Michael Greenberg [this message]
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=83950DC1-1C85-4C0C-804D-FD795F6EA558@pomona.edu \
--to=michael.greenberg@pomona.edu \
--cc=ajb22014@MyMail.pomona.edu \
--cc=dash@vger.kernel.org \
--cc=martijn@inlv.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.
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).