NetBSD Problem Report #50958

From kre@munnari.OZ.AU  Sat Mar 12 18:00:43 2016
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.netbsd.org", Issuer "Postmaster NetBSD.org" (verified OK))
	by mollari.NetBSD.org (Postfix) with ESMTPS id A55BC7A13C
	for <gnats-bugs@www.NetBSD.org>; Sat, 12 Mar 2016 18:00:43 +0000 (UTC)
Message-Id: <201603121800.u2CI060c012570@andromeda.noi.kre.to>
Date: Sun, 13 Mar 2016 01:00:06 +0700 (ICT)
From: kre@munnari.OZ.AU
To: gnats-bugs@www.NetBSD.org
Subject: /bin/sh $(( )) does not support ?: or assignment operators
X-Send-Pr-Version: 3.95

>Number:         50958
>Category:       bin
>Synopsis:       /bin/sh $(( )) does not support ?: or assignment operators
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kre
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Sat Mar 12 18:05:00 +0000 2016
>Closed-Date:    Thu Mar 23 11:29:03 +0000 2017
>Last-Modified:  Thu Mar 23 11:29:03 +0000 2017
>Originator:     Robert Elz
>Release:        NetBSD 7.99.26 (any version up to date of PR).
>Organization:
>Environment:
System: NetBSD andromeda.noi.kre.to 7.99.26 NetBSD 7.99.26 (VBOX64-1.1-20160128) #43: Thu Jan 28 16:09:08 ICT 2016 kre@onyx.coe.psu.ac.th:/usr/obj/current/kernels/amd64/VBOX64 amd64
Architecture: x86_64
Machine: amd64
>Description:
	According to POSIX, the expressions in $(( )) evaluation should
	allow anything permitted in C expressions, except that ++ and --
	(prefix or postfix) are not required (and not implemented, though
	they would be useful) and sizeof (which wouldn't be rational.)
	(Support is only required for signed integers, which is fine.)

	NetBSD's /bin/sh does not support ?: or any of the assignment
	operators.

>How-To-Repeat:
		/bin/sh -c 'echo $(( 1 ? 2 : 3 ))'
		sh: arith: syntax error: " 1 ? 2 : 3 "

		/bin/sh -c 'echo $(( x=3 ))'
		sh: arith: syntax error: " x=3 "
	(etc).

>Fix:
	This is another "placeholder" PR...   I have a fix for ?:
	(actually wanted to use it in a script, only to discover it
	didn't work...)

	The assignment ops will get worked on in time...
	May even include ++ and -- support at the same time, if it
	looks reasonable (they're not prohibited, just not required.)

>Release-Note:

>Audit-Trail:
From: "Christos Zoulas" <christos@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50958 CVS commit: src/bin/sh
Date: Wed, 16 Mar 2016 11:42:33 -0400

 Module Name:	src
 Committed By:	christos
 Date:		Wed Mar 16 15:42:33 UTC 2016

 Modified Files:
 	src/bin/sh: arith.y arith_lex.l

 Log Message:
 PR/50958: (partial fix) - support ?: expressions in arith expansions
 (from kre)


 To generate a diff of this commit:
 cvs rdiff -u -r1.22 -r1.23 src/bin/sh/arith.y
 cvs rdiff -u -r1.17 -r1.18 src/bin/sh/arith_lex.l

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: bin-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Thu, 16 Mar 2017 19:35:19 +0000
Responsible-Changed-Why:
I am looking into this PR


From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50958 CVS commit: src/bin/sh
Date: Mon, 20 Mar 2017 11:26:07 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Mon Mar 20 11:26:07 UTC 2017

 Modified Files:
 	src/bin/sh: Makefile expand.c expand.h sh.1
 Added Files:
 	src/bin/sh: arith_token.c arith_tokens.h arithmetic.c arithmetic.h
 Removed Files:
 	src/bin/sh: arith.y arith_lex.l

 Log Message:
 Finish support for all required $(( )) (shell arithmetic) operators,
 closing PR bin/50958

 That meant adding the assignment operators ('=', and all of the +=, *= ...)
 Currently, ++, --, and ',' are not implemented (none of those are required
 by posix) but support for them (most likely ',' first) might be added later.

 To do this, I removed the yacc/lex arithmetic parser completely, and
 replaced it with a hand written recursive descent parser, that I obtained
 from FreeBSD, who earlier had obtained it from dash (Herbert Xu).

 While doing the import, I cleaned up the sources (changed some file names
 to avoid requiring a clean build, or signifigant surgery to the obj
 directories if "build.sh -u" was to be used - "build.sh -u" should work
 fine as it is now) removed some dashisms, applied some KNF, ...


 To generate a diff of this commit:
 cvs rdiff -u -r1.103 -r1.104 src/bin/sh/Makefile
 cvs rdiff -u -r1.25 -r0 src/bin/sh/arith.y
 cvs rdiff -u -r1.18 -r0 src/bin/sh/arith_lex.l
 cvs rdiff -u -r0 -r1.1 src/bin/sh/arith_token.c src/bin/sh/arith_tokens.h \
     src/bin/sh/arithmetic.c src/bin/sh/arithmetic.h
 cvs rdiff -u -r1.102 -r1.103 src/bin/sh/expand.c
 cvs rdiff -u -r1.19 -r1.20 src/bin/sh/expand.h
 cvs rdiff -u -r1.125 -r1.126 src/bin/sh/sh.1

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

From: "Robert Elz" <kre@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/50958 CVS commit: src/tests/bin/sh
Date: Mon, 20 Mar 2017 11:32:51 +0000

 Module Name:	src
 Committed By:	kre
 Date:		Mon Mar 20 11:32:51 UTC 2017

 Modified Files:
 	src/tests/bin/sh: t_arith.sh

 Log Message:
 Add tests for the $(( )) assignment operators  PR bin/50958


 To generate a diff of this commit:
 cvs rdiff -u -r1.5 -r1.6 src/tests/bin/sh/t_arith.sh

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: open->closed
State-Changed-By: kre@NetBSD.org
State-Changed-When: Thu, 23 Mar 2017 11:29:03 +0000
State-Changed-Why:
All required operators are now supported.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2014 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.