Manual Page Result
0
Command: expr | Section: 1 | Source: UNIX v10 | File: expr.1
EXPR(1) General Commands Manual EXPR(1)
NAME
expr - integer and string-match expression evaluator for shell scripts
SYNOPSIS
expr arg ...
DESCRIPTION
The arguments are taken as an expression. After evaluation, the result
is written on the standard output. Each token of the expression is a
separate argument.
The operators and keywords are listed below in order of increasing
precedence, with equal precedence operators grouped.
expr1 | expr2
Value is the value of expr1 if that is neither empty nor 0,
otherwise the value of expr2.
expr1 & expr2
Value is the value of expr1 if neither expr1 nor expr2 is
empty or 0, otherwise 0.
expr1 relop expr2
Relop is one of Value is 1 if the indicated comparison is
true, 0 if false. The comparison is numeric if both expr are
integers, otherwise lexicographic.
expr1 + expr2
expr1 - expr2
Value is the sum or difference of the (integer) values of
expr1 and expr2.
expr1 * expr2
expr1 / expr2
expr1 % expr2
Value is the product, quotient, or remainder of the (integer)
values of expr1 and expr2.
expr : regexp
Match the string value of expr with the regular expression
regexp; regular expression syntax is the same as in ed(1), but
matches are anchored at the left. On success a subexpression
\(...\), if present in regexp, picks out a return value from
the matched string. Otherwise, the matching operator yields
the number of characters matched (0 on failure).
( expr ) Parentheses for grouping.
arg Value is the string arg.
EXAMPLES
a=`expr $a + 1`
Add 1 to shell variable a.
expr $a : '.*/\(.*\)' '|' $a
Same as
SEE ALSO
sh(1), test(1)
DIAGNOSTICS
Expr returns exit code 0 if the expression is neither null nor 0, 1 if
the expression is null or 0, 2 for invalid expressions.
EXPR(1)