Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 5 Jun 2003 20:03:16 +0200 (CEST)
From:      Jens Schweikhardt <schweikh@schweikhardt.net>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   standards/52972: /bin/sh arithmetic not POSIX compliant
Message-ID:  <200306051803.h55I3GIT055188@hal9000.schweikhardt.net>
Resent-Message-ID: <200306051810.h55IAADg069159@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         52972
>Category:       standards
>Synopsis:       /bin/sh arithmetic not POSIX compliant
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-standards
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 05 11:10:09 PDT 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jens Schweikhardt
>Release:        FreeBSD 5.1-BETA i386
>Organization:
Digital Details
>Environment:
System: FreeBSD hal9000.schweikhardt.net 5.1-BETA FreeBSD 5.1-BETA #0: Wed May 21 20:30:29 CEST 2003 toor@hal9000.schweikhardt.net:/usr/obj/share/src/HEAD/sys/HAL9000 i386


	Any.
>Description:
	/bin/sh implements only a subset of the operators in $(( ... )) arithmetic.
	It also does not understand variable names in arithmetic expressions.

	This missing feature makes it impossible to run the OpenGroup's POSIX
	validation test suite because the configuration process for the test suite
	expects a POSIX system shell and makes heavy use of $((var += number)).
	[I can't just edit the scripts in question to use zsh or ksh93 because
	the configuration process involves executables calling system(3), make(1) etc
	which use /bin/sh hardcoded. Replacing /bin/sh is not an option.]

>How-To-Repeat:
$ /bin/sh
$ a=1
$ echo $((a + 1))                    # should echo 2
arith: syntax error: "a + 1"

$ echo $((a += 1))                   # should echo 2 and increment a
arith: syntax error: "a += 1"

IEEE Std 1003.2-2001 requires the other 'op=' assignment operators as well.

The zsh and ksh93 get this right:
$ a=1
$ echo $((a + 1))
2
$ echo $((a += 1))
2
$ echo $a
2

>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted:


Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200306051803.h55I3GIT055188>