
Arithmetic Expressions | 643
Bash and Korn
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
In addition, some or all of the PS1–PS4 variables undergo different substitutions,
as outlined in the following table.
In Bash, the escape sequences are processed first, and then, if the promptvars
shell option is enabled via the shopt command (the default), the substitutions are
performed.
Arithmetic Expressions
The let command performs arithmetic. ksh88 and Bash are restricted to integer
arithmetic. ksh93 can do floating-point arithmetic as well. Both shells provide a
way to substitute arithmetic values (for use as command arguments or in vari-
ables); base conversion is also possible.
Operators
The shells use arithmetic operators from the C programming language; the
following table listing is in decreasing order of precedence. ksh88 does not
support the ++, --, unary +, ?:, comma or ** operators. Early versions of ksh93 do
not have **.
Substitution ksh88 ksh93 Bash
! for command number PS1 PS1
Escape sequences PS1, PS2, PS4
Variable substitution PS1 PS1 PS1, PS2, PS4
Command substitution PS1 PS1, PS2, PS4
Arithmetic substitution PS1 PS1, PS2, PS4
Expression Meaning
$(( expr )) Use the value of the enclosed arithmetic expression.
B#n Interpret integer n in numeric base B. For example, 8#100 specifies the octal equivalent of decimal 64.
Operator Description ...