Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

Arithmetic evaluation

&pagelevel(4)&pagelevel

The built-in let command provides a mechanism for performing integer arithmetic. Evaluations are performed using long arithmetic. Constants are of the form [base#]n, where base is a decimal number between two and thirty-six representing the arithmetic base: n is a number in that base. If base# is omitted, base 10 is used.

An arithmetic expression uses much the same syntax, precedence, and associativity as the C language. All the integral operators, other than ++, --, ?, : and the comma are supported. Variables can be referenced by name within an arithmetic expression without using the parameter substitution syntax (the $ character). When a variable is referenced, its value is evaluated as an arithmetic expression.

An internal integer representation of a variable can be specified as an attribute with the -i option of the built-in typeset command. Arithmetic evaluation is performed on the value of each assignment to a variable with the -i attribute. If you do not specify an arithmetic base, the first assignment to the variable determines the arithmetic base. This base is used when parameter substitution is performed.

Since many of the arithmetic operators must be quoted for the POSIX shell, an alternative form of the let command is provided. For any command which begins with a double left parenthesis ((, all the characters until a matching double right parenthesis )) are treated as a quoted expression. Thus ((a=a+b)) is equivalent to let "a=a+b".