[BACK]Return to expr.1 CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / bin / expr

Annotation of src/bin/expr/expr.1, Revision 1.9

1.9     ! jtc         1: .\"    $NetBSD: expr.1,v 1.8 1995/03/21 09:05:37 cgd Exp $
1.8       cgd         2: .\"
1.9     ! jtc         3: .\" Written by J.T. Conklin <jtc@netbsd.org>.
        !             4: .\" Public domain.
1.1       jtc         5: .\"
                      6: .Dd July 3, 1993
                      7: .Dt EXPR 1
                      8: .Os
                      9: .Sh NAME
                     10: .Nm expr
                     11: .Nd evaluate expression
                     12: .Sh SYNOPSIS
                     13: .Nm expr
                     14: .Ar expression
                     15: .Sh DESCRIPTION
                     16: The
                     17: .Nm expr
                     18: utility evaluates
                     19: .Ar expression
                     20: and writes the result on standard output.
                     21: .Pp
                     22: All operators are separate arguments to the
                     23: .Nm expr
                     24: utility.
                     25: Characters special to the command interpreter must be escaped.
                     26: .Pp
1.6       jtc        27: Operators are listed below in order of increasing precedence.
                     28: Operators with equal precedence are grouped within { } symbols.
1.1       jtc        29: .Bl -tag -width indent
                     30: .It Ar expr1 Li | Ar expr2
                     31: Returns the evaluation of
                     32: .Ar expr1
                     33: if it is neither an empty string nor zero;
                     34: otherwise, returns the evaluation of
                     35: .Ar expr2 .
                     36: .It Ar expr1 Li & Ar expr2
                     37: Returns the evaluation of
                     38: .Ar expr1
                     39: if neither expression evaluates to an empty string or zero;
                     40: otherwise, returns zero.
                     41: .It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2
1.6       jtc        42: Returns the results of integer comparison if both arguments are integers;
1.3       jtc        43: otherwise, returns the results of string comparison using the locale-specific
                     44: collation sequence.
1.1       jtc        45: The result of each comparison is 1 if the specified relation is true,
                     46: or 0 if the relation is false.
                     47: .It Ar expr1 Li "{+, -}" Ar expr2
                     48: Returns the results of addition or subtraction of integer-valued arguments.
                     49: .It Ar expr1 Li "{*, /, %}" Ar expr2
                     50: Returns the results of multiplication, integer division, or remainder of integer-valued arguments.
                     51: .It Ar expr1 Li : Ar expr2
                     52: The
                     53: .Dq \:
                     54: operator matches
                     55: .Ar expr1
                     56: against
                     57: .Ar expr2 ,
                     58: which must be a regular expression.  The regular expression is anchored
1.6       jtc        59: to the beginning of  the string with an implicit
1.5       jtc        60: .Dq ^ .
1.1       jtc        61: .Pp
1.5       jtc        62: If the match succeeds and the pattern contains at least one regular
                     63: expression subexpression
1.1       jtc        64: .Dq "\e(...\e)" ,
                     65: the string corresponding to
                     66: .Dq "\e1"
                     67: is returned;
                     68: otherwise the matching operator returns the number of characters matched.
1.5       jtc        69: If the match fails and the pattern contains a regular expression subexpression
                     70: the null string is returned;
                     71: otherwise 0.
1.1       jtc        72: .El
                     73: .Pp
                     74: Parentheses are used for grouping in the usual manner.
                     75: .Sh EXAMPLES
                     76: .Bl -enum
                     77: .It
                     78: The following example adds one to the variable a.
                     79: .Dl a=`expr $a + 1`
                     80: .It
                     81: The following example returns the filename portion of a pathname stored
                     82: in variable a.  The // characters act to eliminate ambiguity with the
                     83: division operator.
                     84: .Dl expr "//$a" Li : '.*/\e(.*\e)'
                     85: .It
                     86: The following example returns the number of characters in variable a.
                     87: .Dl expr $a Li : '.*'
                     88: .El
                     89: .Sh DIAGNOSTICS
                     90: The
                     91: .Nm expr
                     92: utility exits with one of the following values:
1.5       jtc        93: .Bl -tag -width Ds -compact
1.1       jtc        94: .It 0
                     95: the expression is neither an empty string nor 0.
                     96: .It 1
                     97: the expression is an empty string or 0.
                     98: .It 2
                     99: the expression is invalid.
                    100: .El
                    101: .Sh STANDARDS
                    102: The
                    103: .Nm expr
1.4       jtc       104: utility conforms to
                    105: .St -p1003.2 .

CVSweb <webmaster@jp.NetBSD.org>