Command Reference Guide

__________________________________________________________________________________________________________________________________________________________________________________________________
__________________________________________________________________________________________________________________________________________________________________________________________________
STANDARD Printed by: Nora Chuang [nchuang] STANDARD
/build/1111/BRICK/man1/!!!intro.1
________________________________________________________________
___ ___
e
expr(1) expr(1)
International Code Set Support
Single- and multi-byte character code sets are supported.
RETURN VALUE
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 Invalid expression.
>2 An error occurred while evaluatingthe expression.
DIAGNOSTICS
syntax error Operator or operand errors
non-numeric argument Arithmetic attempted on a string
EXAMPLES
Add 1 to the shell variable a:
a=‘expr $a + 1‘
For $a equal to either /usr/abc/file
or just file, return the last segment of a path name (i.e.,
file). Beware of / alone as an argument because expr interprets it as the division operator (see
WARN-
INGS
below):
expr $a : ’.*/\(.*\)’ \| $a
A better representation of the previous example. The addition of the
// characters eliminates any ambi-
guity about the division operator and simplifies the whole expression:
expr //$a : ’.*/\(.*\)’
Return the number of characters in $VAR:
expr $VAR : ’.*’
WARNINGS
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 =, the command:
expr $a = ’=’
resembles:
expr = = =
as the arguments are passed to expr (and they will all be taken as the = operator). The following works:
expr X$a = X=
AUTHOR
expr was developed by OSF and HP.
SEE ALSO
sh(1), test(1), environ(5), lang(5), regexp(5).
STANDARDS CONFORMANCE
expr: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
HP-UX Release 11i: December 2000 2 Section 1263
___
___