NetBSD-Users archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Arithmetic Expansion in shell.



NetBSD-users,
I am trying to understand what I am doing wrong when using sh but not ksh.
In /bin/ksh I type:
echo $(( i=i+1 ))
I get the next value for i.

In /bin/sh ,  I type the same thing:
echo $(( i=i+1 ))
I get this;  arith: syntax error: " i=i+1 "

Here is an excerpt from man sh:
----8<----------------8<----
 Arithmetic Expansion
    Arithmetic expansion provides a mechanism for evaluating an arithmetic
expression and substituting its value. The format for arithmetic expan-
    sion is as follows:

          $((expression))
   ...

Shell variables may be referenced by name inside an arithmetic expression, without needing a
    ``$'' sign.
----8<----------------8<----

So what is the syntax supposed to be for /bin/sh?

Thanks,
Glen


Home | Main Index | Thread Index | Old Index