home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / shu194st.zoo / shellutils-1.9.4 / man / expr.man < prev    next >
Encoding:
Text File  |  1994-03-16  |  4.5 KB  |  129 lines

  1.  
  2.  
  3.  
  4. EXPR(1L)                         EXPR(1L)
  5.  
  6.  
  7. N✓NA✓AM✓ME✓E
  8.        expr - evaluate expressions
  9.  
  10. S✓SY✓YN✓NO✓OP✓PS✓SI✓IS✓S
  11.        e✓ex✓xp✓pr✓r expression...
  12.        e✓ex✓xp✓pr✓r {--help,--version}
  13.  
  14. D✓DE✓ES✓SC✓CR✓RI✓IP✓PT✓TI✓IO✓ON✓N
  15.        This  manual page documents the GNU version of e✓ex✓xp✓pr✓r.  e✓ex✓xp✓pr✓r
  16.        evaluates an expression and writes the result on    its stan-
  17.        dard output.  Each token    of the expression must be a sepa-
  18.        rate argument.  Operands    are either  numbers  or     strings.
  19.        Strings    are  not  quoted for e✓ex✓xp✓pr✓r, though you may need to
  20.        quote them to protect them from the shell.   e✓ex✓xp✓pr✓r  coerces
  21.        anything    appearing in an    operand    position to an integer or
  22.        a string    depending on the operation being applied to it.
  23.  
  24.        The operators (in order of increasing precedence) are:
  25.  
  26.        _✓|      Yields its first argument    if it is neither null nor
  27.           0,  otherwise  its  second  argument.   This is the
  28.           usual `or' operation.
  29.  
  30.        _✓&      Yields its first argument    if  neither  argument  is
  31.           null or 0, otherwise 0.
  32.  
  33.        _✓<  _✓<_✓=  _✓=     _✓=_✓=  _✓!_✓=     _✓>_✓=  _✓>
  34.           Compare  their  arguments    and return 1 if    the rela-
  35.           tion is true, 0 otherwise.  (_✓=_✓= is  a  synonym  for
  36.           _✓=.)  e✓ex✓xp✓pr✓r    tries to coerce    both arguments to numbers
  37.           and do a numeric comparison; if it fails when  try-
  38.           ing  to coerce either argument it    then does a lexi-
  39.           cographic    comparison.
  40.  
  41.        _✓+  _✓-   Perform arithmetic operations.  Both arguments  are
  42.           coerced  to numbers; an error occurs if this cannot
  43.           be done.
  44.  
  45.        _✓*  _✓/  _✓%
  46.           Perform arithmetic operations (`%' is the    remainder
  47.           operation, as in C).  Both arguments are coerced to
  48.           numbers; an error    occurs if this cannot be done.
  49.  
  50.        _✓:      Perform  pattern    matching.   Its      arguments   are
  51.           coerced to strings and the second    one is considered
  52.           to be a regular expression, with a  `^'  implicitly
  53.           added at the beginning.  The first argument is then
  54.           matched against this regular  expression.      If  the
  55.           match  succeeds  and part    of the string is enclosed
  56.           in `\(' and `\)',    that part is the value of  the    _✓:
  57.           expression; otherwise an integer whose value is the
  58.           number of    characters matched is returned.      If  the
  59.           match fails, the _✓: operator returns the null string
  60.           if `\(' and `\)' are used, otherwise 0.    Only  one
  61.  
  62.  
  63.  
  64. FSF               GNU Shell Utilities            1
  65.  
  66.  
  67.  
  68. EXPR(1L)                         EXPR(1L)
  69.  
  70.  
  71.           `\(' and `\)' pair can be    used.
  72.  
  73.        In addition, the    following keywords are recognized:
  74.  
  75.        m✓ma✓at✓tc✓ch✓h _✓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.        s✓su✓ub✓bs✓st✓tr✓r _✓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.        i✓in✓nd✓de✓ex✓x _✓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.        l✓le✓en✓ng✓gt✓th✓h _✓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.    O✓OP✓PT✓TI✓IO✓ON✓NS✓S
  98.        When  GNU  e✓ex✓xp✓pr✓r    is invoked with    exactly    one argument, the
  99.        following options are recognized:
  100.  
  101.        _✓-_✓-_✓h_✓e_✓l_✓p Print a usage message on standard    output    and  exit
  102.           successfully.
  103.  
  104.        _✓-_✓-_✓v_✓e_✓r_✓s_✓i_✓o_✓n
  105.           Print  version  information on standard output then
  106.           exit successfully.
  107.  
  108. E✓EX✓XA✓AM✓MP✓PL✓LE✓ES✓S
  109.        To add 1    to the shell variable _✓a:
  110.  
  111.           a=`expr $a + 1`
  112.  
  113.        To find the filename part of the    pathname stored    in  vari-
  114.        able _✓a, which may or may    not contain `/':
  115.  
  116.           expr $a :    '.*/\(.*\)' '|'    $a
  117.  
  118.        Note the    quoted shell metacharacters.
  119.  
  120.        e✓ex✓xp✓pr✓r returns the    following exit status:
  121.  
  122.        0 if the    expression is neither null nor 0,
  123.        1 if the    expression is null or 0,
  124.        2 for invalid expressions.
  125.  
  126.  
  127.  
  128. FSF               GNU Shell Utilities            2
  129.