The Korn shell's let command performs arithmetic. ksh88 is restricted to integer arithmetic. ksh93 can do floating-point arithmetic as well. The Korn shell provides a way to substitute arithmetic values (for use as command arguments or in variables); base conversion is also possible:
| Use the value of the enclosed arithmetic expression. |
B | Interpret integer n in numeric base B. For example, |
The Korn shell uses arithmetic operators from the C programming language; in decreasing order of precedence.
Operator | Description |
---|---|
| Auto-increment and auto-decrement, both prefix and postfix. ksh93 only. |
| |
| |
| |
| |
| Addition; subtraction. |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
ksh93 provides access to the standard set of mathematical functions. They are called using C function call syntax.
Name | Function | Name | Function |
---|---|---|---|
abs | Absolute value | log | Natural logarithm |
acos | Arc cosine | sin | Sine |
asin | Arc sine | sinh | Hyperbolic sine |
cos | Cosine | sqrt | Square root |
cosh | Hyperbolic cosine | tan | Tangent |
exp | Exponential function | tanh | Hyperbolic tangent |
int | Integer part of floating-point number |
See the let command for more information and examples:
let "count=0" "i = i + 1" Assign i and count let "num % 2" Test for an even number (( percent >= 0 && percent <= 100 )) Test the range of a value