shell arithmetic not POSIX compliant

Jens Schweikhardt schweikh at
Mon Jun 2 13:14:32 PDT 2003

hello, world\n

while trying to configure the POSIX validation suite from the OpenGroup
(VSC-lite) I ran into the following problem. During test script generation
the following syntax appears in a shell script:

            : $((tet_l31_testnum += $#))

where tet_l31_testnum is the name of a variable with an integer value
and $# is 1. Our /bin/sh complains about

/home/vsctest1/tet_root/lib/posix_sh/ arith: syntax error: "tet_l31_testnum += 1"

This begs the question is our shell's arithmetic substandard or is the
bug in the script? I'm inclined to say it is a bug in our /bin/sh,
reading the POSIX 2001 sh spec, which refers to the C operators table
and makes these exceptions

<quote IEEE Std 1003.1, 2003 Edition>
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.

</quote IEEE Std 1003.1, 2003 Edition>

So it appears all assignment ops like += must be supported.


Jens Schweikhardt
SIGSIG -- signature too long (core dumped)

More information about the freebsd-standards mailing list