MPE/iX Shell and Utilities Reference Manual, Vol 1

expr(1) MPE/iX Shell and Utilities expr(1)
NAME
expr — evaluate expression
SYNOPSIS
expr expression
DESCRIPTION
The set of arguments passed to expr constitutes an expression to be evaluated. Each com-
mand argument is a separate token of the expression. expr writes the result of the expression
on the standard output. This command is primarily intended for arithmetic and string manipu-
lation on shell variables.
expr recognizes the following operators. Operators listed together have equal precedence;
otherwise, they are in increasing order of precedence. expr stores expressions as strings and
converts them to numbers during the operation. If the context requires a Boolean value, a
numeric value of 0 (zero) or a null string ("") is false, and any other value is true. Numbers
have an optional leading sign, followed by 0 for octal, 0x for hexadecimal, otherwise deci-
mal, followed by the digits of the number. Numbers are manipulated as long integers.
expr1 expr2
results in the value expr1 if expr1 is true; otherwise it results in the value of expr2.
expr1 & expr2
results in the value of expr1 if both expressions are true; otherwise it results in 0
expr1 <= expr2
expr1 < expr2
expr1 = expr2
expr1 != expr2
expr1 >= expr2
expr1 > expr2
If both expr1 and expr2 are numeric, *[CMD expr] compares them as numbers;
otherwise it compares them as strings. If the comparison is true, the expression
results in 1; otherwise it results in 0.
expr1 + expr2
expr1 expr2
performs addition or subtraction on the two expressions. If either expression is not a
number, expr exits with an error.
Commands and Utilities 1-219