home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / gcc / gcc260utilsdoc.lha / gnu / man / man1 / expr.1 < prev    next >
Encoding:
Text File  |  1994-07-26  |  5.3 KB  |  199 lines

  1.  
  2.  
  3.  
  4. EXPR(1L)          Misc. Reference Manual Pages           EXPR(1L)
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      expr - evaluate expressions
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      eeeexxxxpppprrrr expression...
  13.      eeeexxxxpppprrrr {--help,--version}
  14.  
  15. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  16.      This manual page documents the GNU version  of  eeeexxxxpppprrrr.   eeeexxxxpppprrrr
  17.      evaluates  an  expression and writes the result on its stan-
  18.      dard output.   Each  token  of  the  expression  must  be  a
  19.      separate  argument.  Operands are either numbers or strings.
  20.      Strings are not quoted for eeeexxxxpppprrrr,  though  you  may  need  to
  21.      quote  them  to  protect  them from the shell.  eeeexxxxpppprrrr coerces
  22.      anything appearing in an operand position to an integer or a
  23.      string depending on the operation being applied to it.
  24.  
  25.      The operators (in order of increasing precedence) are:
  26.  
  27.      |    Yields its first argument if it is neither null nor  0,
  28.           otherwise  its second argument.  This is the usual `or'
  29.           operation.
  30.  
  31.      &    Yields its first argument if neither argument  is  null
  32.           or 0, otherwise 0.
  33.  
  34.      <  <=  =  ==  !=  >=  >
  35.           Compare their arguments and return 1 if the relation is
  36.           true,  0  otherwise.   (==  is  a synonym for =.)  eeeexxxxpppprrrr
  37.           tries to coerce both arguments  to  numbers  and  do  a
  38.           numeric  comparison;  if it fails when trying to coerce
  39.           either argument  it  then  does  a  lexicographic  com-
  40.           parison.
  41.  
  42.      +  - Perform  arithmetic  operations.   Both  arguments  are
  43.           coerced  to  numbers; an error occurs if this cannot be
  44.           done.
  45.  
  46.      *  /  %
  47.           Perform arithmetic operations  (`%'  is  the  remainder
  48.           operation,  as  in  C).   Both arguments are coerced to
  49.           numbers; an error occurs if this cannot be done.
  50.  
  51.      :    Perform pattern matching.  Its arguments are coerced to
  52.           strings  and the second one is considered to be a regu-
  53.           lar expression, with a  `^'  implicitly  added  at  the
  54.           beginning.   The first argument is then matched against
  55.           this regular expression.  If  the  match  succeeds  and
  56.           part  of  the string is enclosed in `\(' and `\)', that
  57.           part is the value of the  :  expression;  otherwise  an
  58.           integer whose value is the number of characters matched
  59.           is returned.  If  the  match  fails,  the  :   operator
  60.  
  61.  
  62.  
  63. FSF             Last change: GNU Shell Utilities                1
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. EXPR(1L)          Misc. Reference Manual Pages           EXPR(1L)
  71.  
  72.  
  73.  
  74.           returns the null string if `\(' and `\)' are used, oth-
  75.           erwise 0.  Only one `\(' and `\)' pair can be used.
  76.  
  77.      In addition, the following keywords are recognized:
  78.  
  79.      mmmmaaaattttcccchhhh _s_t_r_i_n_g _r_e_g_e_x
  80.           An alternative way to do pattern matching.  This is the
  81.           same as ``_s_t_r_i_n_g :::: _r_e_g_e_x''.
  82.  
  83.      ssssuuuubbbbssssttttrrrr _s_t_r_i_n_g _p_o_s_i_t_i_o_n _l_e_n_g_t_h
  84.           Return the substring of _s_t_r_i_n_g  beginning  at  _p_o_s_i_t_i_o_n
  85.           with  length  at  most  _l_e_n_g_t_h.   If either _p_o_s_i_t_i_o_n or
  86.           _l_e_n_g_t_h  is  negative  or  non-numeric,  return  a  null
  87.           string.
  88.  
  89.      iiiinnnnddddeeeexxxx _s_t_r_i_n_g _c_h_a_r_a_c_t_e_r-_c_l_a_s_s
  90.           Return the first position in  _s_t_r_i_n_g  where  the  first
  91.           character  in _c_h_a_r_a_c_t_e_r-_c_l_a_s_s was found.  If no charac-
  92.           ter 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.
  93.  
  94.      lllleeeennnnggggtttthhhh _s_t_r_i_n_g
  95.           Return the length of _s_t_r_i_n_g.
  96.  
  97.      Parentheses are used for grouping in the usual manner.   The
  98.      keywords cannot be used as strings.
  99.  
  100.   OOOOPPPPTTTTIIIIOOOONNNNSSSS
  101.      When GNU eeeexxxxpppprrrr is invoked with exactly one argument, the fol-
  102.      lowing options are recognized:
  103.  
  104.      --_h_e_l_p
  105.           Print a usage message on standard output and exit  suc-
  106.           cessfully.
  107.  
  108.      --_v_e_r_s_i_o_n
  109.           Print version information on standard output then  exit
  110.           successfully.
  111.  
  112. EEEEXXXXAAAAMMMMPPPPLLLLEEEESSSS
  113.      To add 1 to the shell variable _a:
  114.  
  115.           a=`expr $a + 1`
  116.  
  117.      To find the filename part of the pathname stored in variable
  118.      _a, which may or may not contain `/':
  119.  
  120.           expr $a : '.*/\(.*\)' '|' $a
  121.  
  122.      Note the quoted shell metacharacters.
  123.  
  124.      eeeexxxxpppprrrr returns the following exit status:
  125.  
  126.  
  127.  
  128.  
  129. FSF             Last change: GNU Shell Utilities                2
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136. EXPR(1L)          Misc. Reference Manual Pages           EXPR(1L)
  137.  
  138.  
  139.  
  140.      0 if the expression is neither null nor 0,
  141.      1 if the expression is null or 0,
  142.      2 for invalid expressions.
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158.  
  159.  
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.  
  191.  
  192.  
  193.  
  194.  
  195. FSF             Last change: GNU Shell Utilities                3
  196.  
  197.  
  198.  
  199.