standards/52972: /bin/sh arithmetic not POSIX compliant

Jens Schweikhardt schweikh at
Thu Jun 5 11:10:11 PDT 2003

>Number:         52972
>Category:       standards
>Synopsis:       /bin/sh arithmetic not POSIX compliant
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    freebsd-standards
>State:          open
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jun 05 11:10:09 PDT 2003
>Originator:     Jens Schweikhardt
>Release:        FreeBSD 5.1-BETA i386
Digital Details
System: FreeBSD 5.1-BETA FreeBSD 5.1-BETA #0: Wed May 21 20:30:29 CEST 2003 toor at i386

	/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.]

$ /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))
$ echo $((a += 1))
$ echo $a


More information about the freebsd-standards mailing list