Starting with ksh93m, the built-in arithmetic facility understands a large percentage of the C language's expressions. This makes the shell more attractive as a full-blown programming language. The following features are available:
$ typeset -i c $ for ((c = 'a'; c <= 'z'; c++)) > do print $c > done 97 98 99 100 ...
$ print $((010 + 1)) Octal 10 is decimal 8 9 $ print $((0x10 + 1)) Hexadecimal 10 is decimal 16 17
$ typeset -ui u=0 $ let u-- $ print $u 4294967295
Operator | Meaning | Associativity |
---|---|---|
++ -- | Increment and decrement, prefix and postfix | Left to right |
+ - ! ~ | Unary plus and minus; logical and bitwise negation | Right to left |
** | Exponentiation[157] |
Right to left |
* / % | Multiplication, division, and remainder | Left to right |
+ - | Addition and subtraction | Left to right |
<< >> | Bit-shift left and right | Left to right |
< <= > >= | Comparisons | Left to right |
== != | Equal and not equal | Left to right |
& | Bitwise and | Left to right |
^ | Bitwise exclusive-or | Left to right |
| | Bitwise or | Left to right |
&& | Logical and (short circuit) | Left to right |
|| | Logical or (short circuit) | Left to right |
?: | Conditional expression | Right to left |
= += -= *= /= %= &= ^= <<= >>= |
Assignment operators | Right to left |
, | Sequential evaluation | Left to right |
[157] ksh93m and newer. The ** operator is not in the C language.
Copyright © 2003 O'Reilly & Associates. All rights reserved.