

expr                         Command                         expr




Compute a command line expression

eexxpprr _a_r_g_u_m_e_n_t ...

The  arguments to  expr form an  expression.  expr  evaluates the
expression and  writes the result on  the standard output.  Among
other uses,  expr lets the user perform  arithmetic in shell com-
mand files.

Each argument is a separate token in the expression.  An argument
has a logical value `false' if it is a null string or has numeri-
cal value  zero, `true' otherwise.  Integer  arguments consist of
an optional  sign followed  by a  string of decimal  digits.  The
range  of valid  integers is  that of  signed long  integers.  No
check  is made  for  overflow or  illegal arithmetic  operations.
Floating point numbers are not supported.

The following list gives each expr operator and its meaning.  The
list is in  order of increasing operator precedence; operators of
the  same precedence  are  grouped together.   All operators  as-
sociate left  to right except  the unary operators  `!', `-', and
`lleenn', which associate right  to left.  The spaces shown are sig-
nificant - they separate the tokens of the expression.

{ _e_x_p_r_1, _e_x_p_r_2, _e_x_p_r_3 }
     Return expr2  if expr1 is  logically true, and  expr3 other-
     wise.  Alternatively,  { _e_x_p_r_1 , _e_x_p_r_2 }  is equivalent to {
     _e_x_p_r_1 , _e_x_p_r_2 , 00 }.

_e_x_p_r_1 | _e_x_p_r_2
     Return expr1 if it is true, expr2 otherwise.

_e_x_p_r_1 & _e_x_p_r_2
     Return expr1 if both are true, zero otherwise.

_e_x_p_r_1 _r_e_l_a_t_i_o_n _e_x_p_r_2
     Where relation is one of <, <=, >, >=, ==, or !=, return one
     if the relation  is true, zero otherwise.  The comparison is
     numeric  if both  arguments can  be interpreted  as numbers,
     lexicographic  otherwise.  The  lexicographic comparison  is
     the same as strcmp (see string).

_e_x_p_r_1 + _e_x_p_r_2
_e_x_p_r_1 - _e_x_p_r_2
     Add or  subtract the  integer arguments.  The  expression is
     invalid if either expr is not a number.

_e_x_p_r_1 * _e_x_p_r_2
_e_x_p_r_1 / _e_x_p_r_2
_e_x_p_r_1 % _e_x_p_r_2
     Multiply, divide,  or take remainder of  the arguments.  The
     expression is invalid if either expr is not numeric.




COHERENT Lexicon                                           Page 1




expr                         Command                         expr



_e_x_p_r_1 : _e_x_p_r_2
     Match  patterns (regular  expressions).   expr2 specifies  a
     pattern in the syntax used  by ed.  It is compared to expr1,
     which may  be any string.  If the  \(...\) pattern occurs in
     the  regular expression  the matching  operator  returns the
     matched field  from the  string; if  there is more  than one
     \(...\) pattern the extracted fields are concatenated in the
     result.  Otherwise, the matching operator returns the number
     of characters matched.

lleenn _e_x_p_r
     Return  the length  of expr.   It  behaves like  strlen (see
     string).  len is a reserved word in expr.

!_e_x_p_r
     Perform logical  negation: return zero if  expr is true, one
     otherwise.

-_e_x_p_r
     Unary minus:  return the  negative of its  integer argument.
     If the argument is non-numeric the expression is invalid.

( _e_x_p_r )
     Return the expr.  The parentheses allow grouping expressions
     in any desired way.

Several operators have special meanings to the shell sh, and must
be quoted to  be interpreted correctly.  The characters that must
be quoted are { } ( ) < > & | *.

***** See Also *****

commands, ed, sh, test

***** Notes *****

expr returns  zero if the  expression is true, one  if false, and
two if an  error occurs.  In the latter case  an error message is
also printed.


















COHERENT Lexicon                                           Page 2


