standards/52972: /bin/sh arithmetic not POSIX compliant
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
> > > 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:
| 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 126.96.36.199 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 188.8.131.52, which you will find at
the following URL:
Therefore, assignment operators *are* required to work.
Dag-Erling Sm=F8rgrav - des at des.no
More information about the freebsd-standards