


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.  (_=_= is  a  synonym  for
	      _=.)  eexxpprr tries to coerce both arguments to numbers
	      and do a numeric comparison; if it fails when  try-
	      ing  to coerce either argument it then does a lexi-
	      cographic 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.

       _:      Perform  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)


       In addition, the following keywords are recognized:

       mmaattcchh _s_t_r_i_n_g _r_e_g_e_x
	      An alternative way to do pattern matching.  This is
	      the same as ``_s_t_r_i_n_g :: _r_e_g_e_x''.

       ssuubbssttrr _s_t_r_i_n_g _p_o_s_i_t_i_o_n _l_e_n_g_t_h
	      Return the substring of _s_t_r_i_n_g beginning	at  _p_o_s_i_-
	      _t_i_o_n  with  length at most _l_e_n_g_t_h.  If either _p_o_s_i_-
	      _t_i_o_n or _l_e_n_g_t_h is negative or non-numeric, return a
	      null string.

       iinnddeexx _s_t_r_i_n_g _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s
	      Return the first position in _s_t_r_i_n_g where the first
	      character in  _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s  was  found.   If  no
	      character	in  _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s  is found in _s_t_r_i_n_g,
	      return 0.

       lleennggtthh _s_t_r_i_n_g
	      Return the length of _s_t_r_i_n_g.

       Parentheses are used for grouping  in  the  usual  manner.
       The keywords cannot be used as strings.

EEXXAAMMPPLLEESS
       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


