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:

0Expression is neither null nor zero.

1Expression is null or zero.

2Invalid expression.

>2 An error occurred while evaluating the expression.

DIAGNOSTICS

 

Operator or operand errors

syntax error

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 WARNINGS below):

expr $a : '.*/\(.*\)' \ $a

A better representation of the previous example. The addition of the // characters eliminates any ambiguity about the division operator and simpli®es 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

e

HP-UX Release 11i: December 2000

− 2 −

Section 1263