Dash Archive mirror
 help / color / mirror / Atom feed
From: Steffen Nurpmeso <steffen@sdaoden.eu>
To: DASH shell mailing list <dash@vger.kernel.org>
Cc: Robert Elz <kre@munnari.OZ.AU>
Subject: $(()) pre/postfix bug
Date: Sat, 02 Jul 2022 01:14:39 +0200	[thread overview]
Message-ID: <20220701231439.egWzS%steffen@sdaoden.eu> (raw)

Hello.

I am currently writing a $(()) expression parser, using Dijkstra's
two stack algorithm (heavily impressed by the busybox one).

While doing so i encountered diverging behaviour in between
shells, and a bug in dash (and a memory failure in NetBSD 9 ksh).

For my own thing i hope i end up like bash (that is: just do it
(tm)), but the NetBSD and OpenBSD variants i also like, as they
mimic C and give an understandable error message.

I Cc: some of you, just for your interest.

Ciao.

==
Name:         dash
Path:         /usr/ports/core
Version:      0.5.11.5

#?2|kent:$ dash -c '(i=10; echo $((++-+++i)))'
-10
#?2|kent:$ dash -c '(i=10; echo $((+++++i)))'
10
#?0|kent:vm$ dash -c '(i=10; echo $((+ + + ++i)))'
10

==
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)

#?0|kent:$ bash -c '(i=10; echo $((++-+++i)))'
-11

==
BusyBox v1.34.0 (2022-01-03 21:34:20 CET) multi-call binary.

#?0|kent:$ busybox.static sh -c '(i=10; echo $((++-+++i)))'
sh: arithmetic syntax error
#?0|kent:$ busybox.static sh -c '(i=10; echo $((+ + - + ++i)))'
-11

==
FreeBSD 13.1-RELEASE releng/13.1-n250148-fc952ac2212 GENERIC

FreeBSD 13.1
#|f-1301-x86:~$ sh -c '(i=10; echo $((++-+++i)))'
sh: arithmetic expression: expecting primary: "++-+++i"

==
OpenBSD 7.1 (GENERIC.MP) #465: Mon Apr 11 18:03:57 MDT 2022

#?1|o-0701:steffen$ ksh -c '(i=10; echo $((++-+++i)))'
ksh: ++-+++i: ++ requires lvalue
#?1|o-0701:steffen$ ksh -c '(i=10; echo $((+++i)))'
ksh: +++i: ++ requires lvalue
#?1|o-0701:steffen$ ksh -c '(i=10; echo $((++i)))'
11
#?0|o-0701:steffen$ ksh -c '(i=10; echo $((+ + + ++i)))'
11
#?0|o-0701:steffen$ ksh -c '(i=10; echo $((+ + - + ++i)))'
-11

==
NetBSD n-0900 9.0 NetBSD 9.0 (GENERIC) #0: Fri Feb 14 00:06:28 UTC 2020  mkrepro@mkrepro.NetBSD.org:/usr/src/sys/arch/amd64/compile/GENERIC amd64

#?0|n-0900:steffen$ ksh -c '(i=10; echo $((++-+++i)))'
Memory fault
#?2|n-0900:steffen$ sh -c '(i=10; echo $((+++++i)))'
sh: arithmetic expression: incr/decr require var name: "+++++i"
#?2|n-0900:steffen$ sh -c '(i=10; echo $((+ ++i)))'
11
#?0|n-0900:steffen$ sh -c '(i=10; echo $((+ - ++i)))'
-11

--steffen
|
|Der Kragenbaer,                The moon bear,
|der holt sich munter           he cheerfully and one by one
|einen nach dem anderen runter  wa.ks himself off
|(By Robert Gernhardt)

             reply	other threads:[~2022-07-01 23:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 23:14 Steffen Nurpmeso [this message]
2022-07-01 23:36 ` $(()) pre/postfix bug Steffen Nurpmeso
2022-07-02  0:28 ` Robert Elz
2022-07-02  8:20   ` Harald van Dijk

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=20220701231439.egWzS%steffen@sdaoden.eu \
    --to=steffen@sdaoden.eu \
    --cc=dash@vger.kernel.org \
    --cc=kre@munnari.OZ.AU \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).