Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

EXPR(1)

NAME

expr − evaluate arguments as an expression

USAGE

expr arguments

DESCRIPTION

Expr takes the arguments supplied as an expression, evaluates them, and writes the results on the standard output.  Each token of the expression is a separate argument. 

OPERATORS AND KEYWORDS

Expr uses the operators and keywords listed below.  The list is in order of increasing precedence, with equal precedence operators grouped within {} symbols.

expr │ expr Return the first expr if it is neither null nor zero. Otherwise, return the second expr.

expr & expr Return the first expr if neither expr is null or zero, otherwise return zero. 

expr { =, \>, \>=, \<, \<=, != } expr
Return the result of an integer comparison if both arguments are integers.  Otherwise, return the result of a lexical comparison.

expr { +, − } expr Add or subtract integer-valued arguments. 

expr { \∗, /, % } expr Multiply, divide, or remainder, respectively, the integer-valued arguments. 

expr : expr Compare the first argument with the second argument (which must be a regular expression).  Regular expression syntax is the same as that of ed (1), except that all patterns are “anchored” (i.e., begin with a caret, ^).  Therefore, the caret (^) is not a special character in that context.  Normally, the matching operator returns the number of characters matched (zero on failure).  Alternatively, the \(...\) pattern symbols can be used to return a portion of the first argument.

(expr) Parentheses for grouping. 

EXAMPLES

To add 1 to the Shell variable a:

a=`expr $a + 1`

To find the filename part (least significant part) of the pathname stored in variable a, which may or may not contain /:

expr $a : ´.*/\(.*\)´ ´|´ $a

Note the quoted Shell metacharacters. 

DIAGNOSTICS

As a side effect of expression evaluation, expr returns the following exit values:
0Expression is neither null nor zero
1Expression is null or zero
2Expression is invalid

RELATED INFORMATION

sh (1), test (1). 

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026