All of lore.kernel.org
 help / color / mirror / Atom feed
* $(()) pre/postfix bug
@ 2022-07-01 23:14 Steffen Nurpmeso
  2022-07-01 23:36 ` Steffen Nurpmeso
  2022-07-02  0:28 ` Robert Elz
  0 siblings, 2 replies; 4+ messages in thread
From: Steffen Nurpmeso @ 2022-07-01 23:14 UTC (permalink / raw)
  To: DASH shell mailing list; +Cc: Robert Elz

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)

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-07-02  8:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-01 23:14 $(()) pre/postfix bug Steffen Nurpmeso
2022-07-01 23:36 ` Steffen Nurpmeso
2022-07-02  0:28 ` Robert Elz
2022-07-02  8:20   ` Harald van Dijk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.