arg1 operator arg2[
Evaluates arguments as expressions and prints the result. Strings can be compared and searched. Arguments and operators must be separated by spaces. In most cases, an argument is an integer, typed literally or represented by a shell variable. There are three types of operators: arithmetic, relational, and logical. Exit status for expr is 0 (expression is nonzero and nonnull), 1 (expression is 0 or null), or 2 (expression is invalid).
expr is typically used in shell scripts to perform simple mathematics, such as addition or subtraction. It is made obsolete in the Korn shell by that program's built-in arithmetic capabilities.
Use the following operators to produce mathematical expressions whose results are printed:
Multiply the arguments.
Take the remainder when
arg1 is divided by
Addition and subtraction are evaluated last, unless they are grouped inside parentheses. The symbols
) have meaning to the shell, so they must be escaped (preceded by a backslash or enclosed in single or double quotes).
Use relational operators
to compare two arguments. Arguments can also be words, in which case comparisons assume
a < z and
A < Z. If the comparison statement is true, the result is 1; if false, the result is 0. Symbols
> must be escaped.
Are the arguments equal?
Are the arguments different?