EXPR ( 1 ) | USER COMMANDS | EXPR ( 1 ) |
---|

expr - evaluate arguments as an expression

Most of the functionality of **expr** is provided in a more natural way by the shell,
**sh**(1),**expr** is provided primarily for backward compatibility.

Terms of the expression must be separate arguments. A string argument is one that can not be identified as an integer. Integer-valued arguments may be preceded by a unary plus or minus sign. Because many of the operators use characters that have special meaning to the shell, they must be quoted when entered from the shell.

Expressions are formed from the operators listed below in order of increasing precedence within groups. All of the operators are
left associative. The symbols *expr1* and *expr2* represent expressions formed from strings and integers and the
following operators:

*expr1***|***expr2*

Returns the evaluation of*expr1*if it is neither null nor 0, otherwise returns the evaluation of expr2.*expr1***&***expr2*

Returns the evaluation of*expr1*if neither expression evaluates to null or 0, otherwise returns 0.*expr1**op**expr2*

Returns the result of a decimal integer comparison if both arguments are integers; otherwise, returns the result of a string comparison using the locale-specific collation sequence. The result of each comparison will be 1 if the specified relationship is true, or 0 if the relationship is false.*op*can be one of the following:*expr1**op**expr2*

Where*op*is**+**or**-**; addition or subtraction of decimal integer-valued arguments.*expr1**op**expr2*

Where*op*is*****,**/**or**%**; multiplication, division, or remainder of the decimal integer-valued arguments.*expr1***:***expr2*

The matching operator : compares*expr1*with*expr2*, which must be a BRE. Normally, the matching operator returns the number of bytes matched and 0 on failure. However, if the pattern contains at least one sub-expression [\( . . .\)], the string corresponding to \1 will be returned.- (
*expr1*)

Grouping symbols. An expression can be placed within parenthesis to change precedence.**match***string**expr*

Equivalent to*string***:***expr*.**substr***string**pos**length**length*character substring of*string*starting at*pos*(counting from 1).**index***string**chars*

The position in*string*(counting from 1) of the leftmost occurrence of any character in*chars*.**length***string*

The number of characters in*string*.**quote***token*

Treat*token*as a string operand.

**version**

expr (AT&T Research) 2010-08-11**author**

Glenn Fowler <glenn.s.fowler@gmail.com>**author**

David Korn <dgkorn@gmail.com>**copyright**

Copyright © 1992-2012 AT&T Intellectual Property**license**

http://www.eclipse.org/org/documents/epl-v10.html