NAME
     expr - simple expression evaluator

SYNOPSIS expr expression

DESCRIPTION Expr parses an expression provided as arguments and prints the result on the standard output.

Expr recognizes three types of operators, relational operators, arith- metic operators and string operators. The following left-associative bi- nary operators are listed from lowest to highest precedence:

| If the left operand is 0 or the empty string, produce the right operand, otherwise produce the left operand. & If both operands are nonzero and nonempty, produce the left operand; otherwise produce 0. <,<=,=,!=,>=,> If both operands are numbers, produce 1 if the relation holds between the left and right operands, otherwise pro- duce 0. If one or both operands is not a number, compare operands as ASCII strings and produce 1 if the relation holds, otherwise produce 0. +,- Produce the sum (respectively, difference) of the operands. Both operands must be numbers. *,/,% Produce the product (respectively, quotient, remainder) of the operands. Both operands must be numbers. : Match a string (left operand) against a pattern (right operand). Patterns are ed(1)-style regular expressions, implicitly anchored to the start of the string. If the pattern contains matching quoted parentheses, \( and \), then if the string matches the pattern, expr produces the substring which matches the part of the pattern between the parentheses, otherwise it produces the empty string. If the pattern contains no quoted parentheses, expr pro- duces a count of the characters in the string that the pattern matches.

Expr also permits expressions in parentheses. Parentheses permit the us- er to override precedence.

EXAMPLES $ expr 1 + 2 3 $ expr 9 / 3 '&' 9 % 2 3 $ expr 9 / 3 '&' 9 % 3 0 $ expr abcdefg : '[a-e]*' 5 $ expr abcdefg : 'a\([a-e]*\)' bcde $

DIAGNOSTICS first operand `%s' to `%s' is not a number second operand `%s' to `%s' is not a number second operand to `%s' is 0 out of memory error in regular expression: %s internal inconsistency in RE prep syntax error, last argument was `%s'

SEE ALSO bc(1), sed(1), test(1)

BUGS Many of the operators are special to the shells and have to be quoted.

Operators can't be used as (string) operands.

The diagnostic complaints about syntax errors are sometimes quite opaque.

Check out the Unix Man pages Manuals
Hosted by www.Geocities.ws

1