


EXPR(1L)                                                 EXPR(1L)


NNAAMMEE
       expr - evaluate expressions

SSYYNNOOPPSSIISS
       eexxpprr expression...

DDEESSCCRRIIPPTTIIOONN
       This  manual page documents the GNU version of eexxpprr.  eexxpprr
       evaluates an expression and writes the result on its stan-
       dard output.  Each token of the expression must be a sepa-
       rate argument.  Operands are either  numbers  or  strings.
       Strings  are  not  quoted for eexxpprr, though you may need to
       quote them to protect them from the shell.   eexxpprr  coerces
       anything appearing in an operand position to an integer or
       a string depending on the operation being applied to it.

       The operators (in order of increasing precedence) are:

       _|      yields its first argument if it is neither null nor
              0,  otherwise  its  second  argument.   This is the
              usual `or' operation.

       _&      yields its first argument if  neither  argument  is
              null or 0, otherwise 0.

       _< _<_= _= _!_= _>_= _>
              compare their arguments and return `1' if the rela-
              tion is true, 0 otherwise.  eexxpprr  tries  to  coerce
              both arguments to numbers and do a numeric compari-
              son; if it fails when trying to coerce either argu-
              ment it then does a lexicographic comparison.

       _+ _-    perform  arithmetic operations.  Both arguments are
              coerced to numbers; an error occurs if this  cannot
              be done.

       _* _/ _%  perform arithmetic operations (`%' is the remainder
              operation, as in C).  Both arguments are coerced to
              numbers; an error occurs if this cannot be done.

       _:      performs   pattern  matching.   Its  arguments  are
              coerced to strings and the second one is considered
              to  be  a regular expression, with a `^' implicitly
              added at the beginning.  The first argument is then
              matched  against  this  regular expression.  If the
              match succeeds and part of the string  is  enclosed
              in  `\('  and `\)', that part is the value of the _:
              expression; otherwise an integer whose value is the
              number  of  characters matched is returned.  If the
              match fails, the _: operator returns the null string
              if  `\('  and `\)' are used, otherwise 0.  Only one
              `\(' and `\)' pair can be used.





                                                                1





EXPR(1L)                                                 EXPR(1L)


       Parentheses are used for grouping in the usual manner.

       Examples:

       To add 1 to the shell variable _a:

              a=`expr $a + 1`

       To find the filename part of the pathname stored in  vari-
       able _a, which may or may not contain `/':

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

       Note the quoted shell metacharacters.

       eexxpprr returns the following exit status:

       0 if the expression is neither null nor 0,
       1 if the expression is null or 0,
       2 for invalid expressions.





































                                                                2


