hbase

heirloom base
git clone git://git.2f30.org/hbase
Log | Files | Refs | README

expr.1 (5923B)


      1 .\"
      2 .\" Sccsid @(#)expr.1	1.16 (gritter) 2/3/05
      3 .\" Parts taken from expr(1), Unix 7th edition:
      4 .\" Copyright(C) Caldera International Inc. 2001-2002. All rights reserved.
      5 .\"
      6 .\" Redistribution and use in source and binary forms, with or without
      7 .\" modification, are permitted provided that the following conditions
      8 .\" are met:
      9 .\"   Redistributions of source code and documentation must retain the
     10 .\"    above copyright notice, this list of conditions and the following
     11 .\"    disclaimer.
     12 .\"   Redistributions in binary form must reproduce the above copyright
     13 .\"    notice, this list of conditions and the following disclaimer in the
     14 .\"    documentation and/or other materials provided with the distribution.
     15 .\"   All advertising materials mentioning features or use of this software
     16 .\"    must display the following acknowledgement:
     17 .\"      This product includes software developed or owned by Caldera
     18 .\"      International, Inc.
     19 .\"   Neither the name of Caldera International, Inc. nor the names of
     20 .\"    other contributors may be used to endorse or promote products
     21 .\"    derived from this software without specific prior written permission.
     22 .\"
     23 .\" USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
     24 .\" INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
     25 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     26 .\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27 .\" ARE DISCLAIMED. IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
     28 .\" LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
     29 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     30 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     31 .\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     32 .\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     33 .\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     34 .\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     35 .TH EXPR 1 "2/3/05" "Heirloom Toolchest" "User Commands"
     36 .SH NAME
     37 expr \- evaluate arguments as an expression
     38 .SH SYNOPSIS
     39 .B expr
     40 .I arguments
     41 \&.\|.\|.
     42 .SH DESCRIPTION
     43 The arguments are taken as an expression.
     44 After evaluation, the result is written on the standard output.
     45 Each token of the expression is a separate argument.
     46 .PP
     47 The operators and keywords are listed below.
     48 The list is in order of increasing precedence,
     49 with equal precedence operators grouped.
     50 .TP
     51 .I expr | expr
     52 yields the first
     53 .I expr
     54 if it is neither null nor `0', otherwise
     55 yields the second
     56 .I expr.
     57 .TP
     58 .I expr & expr
     59 yields the first
     60 .I expr
     61 if neither
     62 .I expr
     63 is null or `0', otherwise yields `0'.
     64 .TP
     65 .I expr relop expr
     66 where
     67 .I relop is one of
     68 < <= = != >= >,
     69 yields `1' if the indicated comparison is true, `0' if false.
     70 The comparison is numeric if both
     71 .I expr
     72 are integers, otherwise lexicographic.
     73 .TP
     74 .IR expr " + " expr
     75 .br
     76 .IR expr " - " expr
     77 .br
     78 addition or subtraction of the arguments.
     79 .TP
     80 .IR expr " * " expr
     81 .br
     82 .IR expr " / " expr
     83 .br
     84 .IR expr " % " expr
     85 .br
     86 multiplication, division, or remainder of the arguments.
     87 .TP
     88 .IR expr " : " expr
     89 The matching operator compares the string first argument
     90 with the regular expression second argument.
     91 Regular expression syntax is the same as that of
     92 .IR ed (1);
     93 .B /usr/5bin/expr
     94 uses simple regular expressions,
     95 .BR /usr/5bin/posix/expr ,
     96 .BR /usr/5bin/posix2001/expr ,
     97 and
     98 .B /usr/5bin/s42/expr
     99 use basic regular expressions.
    100 The
    101 \fB\\(\|.\|.\|.\|\\)\fP
    102 pattern symbols can be used to select a portion of the
    103 first argument.
    104 Otherwise,
    105 the matching operator yields the number of characters matched
    106 (`0' on failure).
    107 .TP
    108 .RI match " expr expr"
    109 Same as
    110 .IR expr " : " expr .
    111 .TP
    112 .RI ( " expr " )
    113 parentheses for grouping.
    114 .TP
    115 .I string
    116 Yields itself
    117 unless it is part of a larger expression.
    118 With
    119 .BR /usr/5bin/posix/expr
    120 and
    121 .BR /usr/5bin/posix2001/expr ,
    122 all
    123 .I strings
    124 that form valid decimal numbers
    125 are converted to the canonical form.
    126 .PP
    127 The following operators are supported only by
    128 .B /usr/5bin/s42/expr
    129 or if the
    130 .B SYSV3
    131 environment variable is set:
    132 .TP
    133 .RI length " string"
    134 Returns the number of characters in
    135 .IR string .
    136 .TP
    137 .RI substr " string index count"
    138 Returns a string that consists of
    139 .I count
    140 characters
    141 beginning at position
    142 .I index
    143 of
    144 .I string
    145 (starting at 1).
    146 .TP
    147 .RI index " string set"
    148 Returns the index in
    149 .I string
    150 (starting at 1) of the first occurrence
    151 of one of the characters in
    152 .IR set ,
    153 or 0 if no character is found.
    154 .SH "ENVIRONMENT VARIABLES"
    155 .TP
    156 .BR LANG ", " LC_ALL
    157 See locale(7).
    158 .TP
    159 .B LC_COLLATE
    160 Sets the collation sequence for string comparison,
    161 and for range expressions,
    162 equivalence classes, and collation symbols
    163 in basic regular expressions.
    164 .TP
    165 .B LC_CTYPE
    166 Determines the mapping of bytes to characters in regular expressions,
    167 for the match, length, substr, and index operators,
    168 and the availability and composition of character classes
    169 in basic regular expressions.
    170 .TP
    171 .B SYSV3
    172 Enables some additional operators as described above.
    173 .SH EXAMPLES
    174 .PP
    175 To add 1 to the Shell variable
    176 .IR a :
    177 .IP
    178 a=\`expr $a + 1\`
    179 .PP
    180 To find the filename part (least significant part)
    181 of the pathname stored in variable
    182 .I a,
    183 which may or may not contain `/':
    184 .IP
    185 expr "$a" : \'.*/\e(\^.*\e)\' \'\^|\' "$a"
    186 .LP
    187 Note the quoted Shell metacharacters.
    188 .\" Historic example, not to be deleted and useful just because of its errors
    189 Also note that this example generates wrong results
    190 if the result of the substitution is `0'
    191 or if `$a' equals one of the
    192 .I expr
    193 operators.
    194 Be sure that your code avoids such problems
    195 and use
    196 .IR basename (1)
    197 if to actually cut out filename parts.
    198 .SH "SEE ALSO"
    199 ed(1), sh(1), test(1)
    200 .SH DIAGNOSTICS
    201 .I Expr
    202 returns the following exit codes:
    203 .PP
    204 	0	if the expression is neither null nor `0',
    205 .br
    206 	1	if the expression
    207 is null or `0',
    208 .br
    209 	2	for invalid expressions.
    210 .SH NOTES
    211 Integers are treated as 64-bit, 2's complement numbers.