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

Dag-ErlingSmørgrav des at
Mon Jun 23 11:30:15 PDT 2003

The following reply was made to PR standards/52972; it has been noted by GNATS.

From: des at (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=)
To: Wartan Hachaturow <wart at>
Cc: freebsd-gnats-submit at
Subject: Re: standards/52972: /bin/sh arithmetic not POSIX compliant
Date: Mon, 23 Jun 2003 20:24:51 +0200

 Wartan Hachaturow <wart at> writes:
 > I've filed just the same bug against Debian package of ash. This is the
 > answer I got from Herbert Xu, also an upstream of what's called "dash",
 > Debian fork of ash shell (it has just the same behaviour as FreeBSD's=20
 > ash):
 > > > According to SUSv3, shell should implement integer variables in=20
 > > > arithmetic evaluation:
 > >
 > > You're mistaken.  SUSv3 only requires constant arithmetic.  Variables
 > > must be expanded before reaching arithmetic expansion.
 He's wrong.  The full text of section 2.6.4 is:
 | Arithmetic expansion provides a mechanism for evaluating an arithmetic
 | expression and substituting its value. The format for arithmetic
 | expansion shall be as follows:
 | $((expression))
 | The expression shall be treated as if it were in double-quotes, except
 | that a double-quote inside the expression is not treated
 | specially. The shell shall expand all tokens in the expression for
 | parameter expansion, command substitution, and quote removal.
 | Next, the shell shall treat this as an arithmetic expression and
 | substitute the value of the expression. The arithmetic expression
 | shall be processed according to the rules given in Arithmetic
 | Precision and Operations , with the following exceptions:
 |  - Only signed long integer arithmetic is required.
 |  - Only the decimal-constant, octal-constant, and hexadecimal-constant
 |    constants specified in the ISO C standard, Section are
 |    required to be recognized as constants.
 |  - The sizeof() operator and the prefix and postfix "++" and "--"
 |    operators are not required.
 |  - Selection, iteration, and jump statements are not supported.
 | As an extension, the shell may recognize arithmetic expressions beyond
 | those listed. The shell may use a signed integer type with a rank
 | larger than the rank of signed long. The shell may use a real-floating
 | type instead of signed long as long as it does not affect the results
 | in cases where there is no overflow. If the expression is invalid, the
 | expansion fails and the shell shall write a message to standard error
 | indicating the failure.
 Not only is there nothing there about only supporting constant
 artithmetic, but the assignment operators are *not* listed as
 exceptions to the "rules given in Arithmetic Precision and
 Operations", which refers to section, which you will find at
 the following URL:
 Therefore, assignment operators *are* required to work.
 Dag-Erling Sm=F8rgrav - des at

More information about the freebsd-standards mailing list