expr - Evaluate arguments as an expression

Synopsis

expr operand ...

Description

The expr utility evaluates an expression formed by the operands and writes the result to standard output.

Operands

The format of the expression to evaluate is shown as follows. expr, expr1, and expr2 can be decimal integers or strings.

Note:
The six relational expressions return the result of a decimal integer comparison if both arguments are integers. Otherwise, they return the result of a string comparison. The result of each comparison is 1 if the specified relationship is true, or 0 if the relationship is false.
Expression Description
expr1 | expr2 Returns the evaluation of expr1 if it is neither null nor zero; otherwise, returns the evaluation of expr2.
expr1 & expr2 Returns the evaluation of expr1 if neither expression evaluates to null or zero; otherwise, returns zero.
expr1 = expr2 Equal.
expr1 > expr2 Greater than.
expr1 >= expr2 Greater than or equal.
expr1 < expr2 Less than.
expr1 <= expr2 Less than or equal.
expr1 != expr2 Not equal.
expr1 + expr2 Addition of decimal integers.
expr1 - expr2 Subtraction of decimal integers.
expr1 * expr2 Multiplication of decimal integers.
expr1 / expr2 Division of decimal integers.
expr1 % expr2 Remainder of decimal integer division.
expr1 : expr2 Matching expression.
( expr ) Grouping symbols.

Exit status

  • 0 when the expression evaluates to neither null nor zero.
  • 1 when the expression evaluates to null or zero.
  • 2 when the expression is invalid.
  • >2 when an error occurred.

Examples

  1. Evaluate an arithmetic expression.
    expr 10+10*10/10-10
  2. Evaluate a true or false condition.
    expr 10 = 10