1EXPR(1)                     General Commands Manual                    EXPR(1)
2
3
4

NAME

6       expr - evaluate arguments as an expression
7

SYNOPSIS

9       expr arg ...
10

DESCRIPTION

12       The arguments are taken as an expression.  After evaluation, the result
13       is written on the standard output.  Each token of the expression  is  a
14       separate argument.
15
16       The  operators  and keywords are listed below.  The list is in order of
17       increasing precedence, with equal precedence operators grouped.
18
19       expr | expr
20              yields the first expr if it is neither null nor  `0',  otherwise
21              yields the second expr.
22
23       expr & expr
24              yields  the first expr if neither expr is null or `0', otherwise
25              yields `0'.
26
27       expr relop expr
28              where relop is one of < <= = != >= >, yields `1'  if  the  indi‐
29              cated  comparison  is  true,  `0'  if  false.  The comparison is
30              numeric if both expr are integers, otherwise lexicographic.
31
32       expr + expr
33              expr - expr
34              addition or subtraction of the arguments.
35
36       expr * expr
37              expr / expr
38              expr % expr
39              multiplication, division, or remainder of the arguments.
40
41       expr : expr
42              The matching operator compares the string  first  argument  with
43              the  regular expression second argument; regular expression syn‐
44              tax is the same as that of ed(1).  The \(...\)  pattern  symbols
45              can  be  used to select a portion of the first argument.  Other‐
46              wise, the matching operator  yields  the  number  of  characters
47              matched (`0' on failure).
48
49       ( expr )
50              parentheses for grouping.
51
52       Examples:
53
54       To add 1 to the Shell variable a:
55
56              a=`expr $a + 1`
57
58       To  find  the  filename  part  (least significant part) of the pathname
59       stored in variable a, which may or may not contain `/':
60
61              expr $a : ´.*/\(.*\)´ ´|´ $a
62
63       Note the quoted Shell metacharacters.
64

SEE ALSO

66       ed(1), sh(1), test(1)
67

DIAGNOSTICS

69       Expr returns the following exit codes:
70
71            0    if the expression is neither null nor `0',
72            1    if the expression is null or `0',
73            2    for invalid expressions.
74
75
76
77                                                                       EXPR(1)
Impressum