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

Dag-ErlingSmørgrav des at des.no
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 des.no (Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=)
To: Wartan Hachaturow <wart at tepkom.ru>
Cc: freebsd-gnats-submit at freebsd.org
Subject: Re: standards/52972: /bin/sh arithmetic not POSIX compliant
Date: Mon, 23 Jun 2003 20:24:51 +0200

 Wartan Hachaturow <wart at tepkom.ru> 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):
 >=20
 > > > 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:
 |=20
 | $((expression))
 |=20
 | 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.
 |=20
 | 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:
 |=20
 |  - Only signed long integer arithmetic is required.
 |=20
 |  - Only the decimal-constant, octal-constant, and hexadecimal-constant
 |    constants specified in the ISO C standard, Section 6.4.4.1 are
 |    required to be recognized as constants.
 |=20
 |  - The sizeof() operator and the prefix and postfix "++" and "--"
 |    operators are not required.
 |=20
 |  - Selection, iteration, and jump statements are not supported.
 |=20
 | 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 1.7.2.1, which you will find at
 the following URL:
 
 http://www.opengroup.org/onlinepubs/007904975/utilities/xcu_chap01.html#tag=
 _01_07_02_01
 
 Therefore, assignment operators *are* required to work.
 
 DES
 --=20
 Dag-Erling Sm=F8rgrav - des at des.no


More information about the freebsd-standards mailing list