home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / unix / doc / expr.man < prev    next >
Text File  |  1993-06-13  |  5KB  |  133 lines

  1.  
  2.  
  3.  
  4. EXPR(1L)                                                 EXPR(1L)
  5.  
  6.  
  7. NNAAMMEE
  8.        expr - evaluate expressions
  9.  
  10. SSYYNNOOPPSSIISS
  11.        eexxpprr expression...
  12.  
  13. DDEESSCCRRIIPPTTIIOONN
  14.        This  manual page documents the GNU version of eexxpprr.  eexxpprr
  15.        evaluates an expression and writes the result on its stan-
  16.        dard output.  Each token of the expression must be a sepa-
  17.        rate argument.  Operands are either  numbers  or  strings.
  18.        Strings  are  not  quoted for eexxpprr, though you may need to
  19.        quote them to protect them from the shell.   eexxpprr  coerces
  20.        anything appearing in an operand position to an integer or
  21.        a string depending on the operation being applied to it.
  22.  
  23.        The operators (in order of increasing precedence) are:
  24.  
  25.        _|      Yields its first argument if it is neither null nor
  26.               0,  otherwise  its  second  argument.   This is the
  27.               usual `or' operation.
  28.  
  29.        _&      Yields its first argument if  neither  argument  is
  30.               null or 0, otherwise 0.
  31.  
  32.        _<  _<_=  _=  _=_=  _!_=  _>_=  _>
  33.               Compare  their  arguments and return 1 if the rela-
  34.               tion is true, 0 otherwise.  (_=_= is  a  synonym  for
  35.               _=.)  eexxpprr tries to coerce both arguments to numbers
  36.               and do a numeric comparison; if it fails when  try-
  37.               ing  to coerce either argument it then does a lexi-
  38.               cographic comparison.
  39.  
  40.        _+  _-   Perform arithmetic operations.  Both arguments  are
  41.               coerced  to numbers; an error occurs if this cannot
  42.               be done.
  43.  
  44.        _*  _/  _%
  45.               Perform arithmetic operations (`%' is the remainder
  46.               operation, as in C).  Both arguments are coerced to
  47.               numbers; an error occurs if this cannot be done.
  48.  
  49.        _:      Perform  pattern  matching.   Its   arguments   are
  50.               coerced to strings and the second one is considered
  51.               to be a regular expression, with a  `^'  implicitly
  52.               added at the beginning.  The first argument is then
  53.               matched against this regular  expression.   If  the
  54.               match  succeeds  and part of the string is enclosed
  55.               in `\(' and `\)', that part is the value of  the  _:
  56.               expression; otherwise an integer whose value is the
  57.               number of characters matched is returned.   If  the
  58.               match fails, the _: operator returns the null string
  59.               if `\(' and `\)' are used, otherwise 0.   Only  one
  60.               `\(' and `\)' pair can be used.
  61.  
  62.  
  63.  
  64.                                                                 1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. EXPR(1L)                                                 EXPR(1L)
  71.  
  72.  
  73.        In addition, the following keywords are recognized:
  74.  
  75.        mmaattcchh _s_t_r_i_n_g _r_e_g_e_x
  76.               An alternative way to do pattern matching.  This is
  77.               the same as ``_s_t_r_i_n_g :: _r_e_g_e_x''.
  78.  
  79.        ssuubbssttrr _s_t_r_i_n_g _p_o_s_i_t_i_o_n _l_e_n_g_t_h
  80.               Return the substring of _s_t_r_i_n_g beginning  at  _p_o_s_i_-
  81.               _t_i_o_n  with  length at most _l_e_n_g_t_h.  If either _p_o_s_i_-
  82.               _t_i_o_n or _l_e_n_g_t_h is negative or non-numeric, return a
  83.               null string.
  84.  
  85.        iinnddeexx _s_t_r_i_n_g _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s
  86.               Return the first position in _s_t_r_i_n_g where the first
  87.               character in  _c_h_a_r_a_c_t_e_r_-_c_l_a_s_s  was  found.   If  no
  88.               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,
  89.               return 0.
  90.  
  91.        lleennggtthh _s_t_r_i_n_g
  92.               Return the length of _s_t_r_i_n_g.
  93.  
  94.        Parentheses are used for grouping  in  the  usual  manner.
  95.        The keywords cannot be used as strings.
  96.  
  97. EEXXAAMMPPLLEESS
  98.        To add 1 to the shell variable _a:
  99.  
  100.               a=`expr $a + 1`
  101.  
  102.        To  find the filename part of the pathname stored in vari-
  103.        able _a, which may or may not contain `/':
  104.  
  105.               expr $a : '.*/\(.*\)' '|' $a
  106.  
  107.        Note the quoted shell metacharacters.
  108.  
  109.        eexxpprr returns the following exit status:
  110.  
  111.        0 if the expression is neither null nor 0,
  112.        1 if the expression is null or 0,
  113.        2 for invalid expressions.
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                                                 2
  131.  
  132.  
  133.