EXPR(1) DOMAIN/IX Reference Manual (SYS5) EXPR(1)
NAME
expr - evaluate arguments as an expression
USAGE
expr arguments
DESCRIPTION
Expr takes the arguments supplied as an expression, evalu-
ates them, and writes the results on the standard output.
Blank spaces must separate terms of the expression, and
characters special to the Shell must be escaped. Note that
0 is returned to indicate a zero value, rather than the null
string. Strings containing blanks or other special charac-
ters should be quoted. Integer-valued arguments may be pre-
ceded by a unary minus sign. Internally, integers are
treated as 32-bit, two's-complement numbers.
OPERATORS AND KEYWORDS
Expr uses the operators and keywords listed below. Charac-
ters that need to be escaped are preceded by \. 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. Other-
wise, return the second expr.
expr \& expr Return the first expr if nei-
ther expr is null or zero,
otherwise return 0.
expr { =, \>, \>=, \<, \<=, != } expr
Return the result of an
integer comparison if both
arguments are integers, Other-
wise, return the result of a
lexical comparison.
expr { +, - } expr Add or subtract integer-valued
arguments.
expr { \*, /, % } expr Multiply, divide, or remainder
the integer-valued arguments.
expr : expr Compare the first argument
with the second argument
(which must be a regular
expression). Regular expres-
sion syntax is the same as
that of ed (1), except that
all patterns are ``anchored,''
Printed 6/10/85 EXPR-1
EXPR(1) DOMAIN/IX Reference Manual (SYS5) EXPR(1)
that is, begin with a caret
(^). Therefore, in this con-
text, the caret is not a spe-
cial character. Normally, the
matching operator returns the
number of characters matched
(0 on failure). Alterna-
tively, the \(...\) pattern
symbols can be used to return
a portion of the first argu-
ment.
EXAMPLES
To add 1 to the Shell variable a, type the following:
a=`expr $a + 1`
To return the last segment of a pathname (i.e., file), use
this:
# 'For $a equal to either
expr //$a : '.*/\(.*\)'
To return the number of characters in $VAR, execute this
command:
expr $VAR : '.*'
CAUTIONS
After argument processing by the Shell, expr cannot tell the
difference between an operator and an operand, except by the
value. If $a is an equal sign (=), the command:
expr $a = =
looks like:
expr = = =
as the arguments are passed to expr (and they will all be
taken as the = operator). The following works:
expr X$a = X=
EXIT CODE
As a side effect of expression evaluation, expr returns the
following exit values:
0 expression is neither null nor zero
1 expression is null or zero
2 expression is invalid
EXPR-2 Printed 6/10/85
EXPR(1) DOMAIN/IX Reference Manual (SYS5) EXPR(1)
DIAGNOSTICS
``syntax error'' Operator/operand error.
``non-numeric argument''
Arithmetic attempted on a non-numeric
string.
RELATED INFORMATION
ed (1), sh (1).
Printed 6/10/85 EXPR-3