Commit | Line | Data |
---|---|---|
4a42d607 C |
1 | .\" Copyright (c) 1993 Winning Strategies, Inc. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" Redistribution and use in source and binary forms, with or without | |
5 | .\" modification, are permitted provided that the following conditions | |
6 | .\" are met: | |
7 | .\" 1. Redistributions of source code must retain the above copyright | |
8 | .\" notice, this list of conditions and the following disclaimer. | |
9 | .\" 2. Redistributions in binary form must reproduce the above copyright | |
10 | .\" notice, this list of conditions and the following disclaimer in the | |
11 | .\" documentation and/or other materials provided with the distribution. | |
12 | .\" 3. All advertising materials mentioning features or use of this software | |
13 | .\" must display the following acknowledgement: | |
14 | .\" This product includes software developed by Winning Strategies, Inc. | |
15 | .\" 4. The name of the author may not be used to endorse or promote products | |
16 | .\" derived from this software withough specific prior written permission | |
17 | .\" | |
18 | .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
19 | .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
20 | .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
21 | .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
22 | .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
23 | .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
24 | .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
25 | .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 | .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 | .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 | .\" | |
29 | .\" $Header: /b/source/CVS/src/bin/expr/expr.1,v 1.1 1993/07/20 20:16:26 jtc Exp $ | |
30 | .\" | |
31 | .Dd July 3, 1993 | |
32 | .Dt EXPR 1 | |
33 | .Os | |
34 | .Sh NAME | |
35 | .Nm expr | |
36 | .Nd evaluate expression | |
37 | .Sh SYNOPSIS | |
38 | .Nm expr | |
39 | .Ar expression | |
40 | .Sh DESCRIPTION | |
41 | The | |
42 | .Nm expr | |
43 | utility evaluates | |
44 | .Ar expression | |
45 | and writes the result on standard output. | |
46 | .Pp | |
47 | All operators are separate arguments to the | |
48 | .Nm expr | |
49 | utility. | |
50 | Characters special to the command interpreter must be escaped. | |
51 | .Pp | |
52 | Operators are listed below in order of increasing precidence. | |
53 | Operators with equal precidence are grouped within { } symbols. | |
54 | .Bl -tag -width indent | |
55 | .It Ar expr1 Li | Ar expr2 | |
56 | Returns the evaluation of | |
57 | .Ar expr1 | |
58 | if it is neither an empty string nor zero; | |
59 | otherwise, returns the evaluation of | |
60 | .Ar expr2 . | |
61 | .It Ar expr1 Li & Ar expr2 | |
62 | Returns the evaluation of | |
63 | .Ar expr1 | |
64 | if neither expression evaluates to an empty string or zero; | |
65 | otherwise, returns zero. | |
66 | .It Ar expr1 Li "{=, >, >=, <, <=, !=}" Ar expr2 | |
67 | Returns the results of integer comparision if both arguments are integers; | |
68 | otherwise, returns the results of lexical comparison. | |
69 | The result of each comparison is 1 if the specified relation is true, | |
70 | or 0 if the relation is false. | |
71 | .It Ar expr1 Li "{+, -}" Ar expr2 | |
72 | Returns the results of addition or subtraction of integer-valued arguments. | |
73 | .It Ar expr1 Li "{*, /, %}" Ar expr2 | |
74 | Returns the results of multiplication, integer division, or remainder of integer-valued arguments. | |
75 | .It Ar expr1 Li : Ar expr2 | |
76 | The | |
77 | .Dq \: | |
78 | operator matches | |
79 | .Ar expr1 | |
80 | against | |
81 | .Ar expr2 , | |
82 | which must be a regular expression. The regular expression is anchored | |
83 | to the begining of the string with an invisible | |
84 | .Dq ^ , | |
85 | therefore | |
86 | .Dq ^ | |
87 | is not a special character. | |
88 | .Pp | |
89 | If the pattern contains at lest one regular expression | |
90 | subexpression | |
91 | .Dq "\e(...\e)" , | |
92 | the string corresponding to | |
93 | .Dq "\e1" | |
94 | is returned; | |
95 | otherwise the matching operator returns the number of characters matched. | |
96 | .El | |
97 | .Pp | |
98 | Parentheses are used for grouping in the usual manner. | |
99 | .Sh EXAMPLES | |
100 | .Bl -enum | |
101 | .It | |
102 | The following example adds one to the variable a. | |
103 | .Dl a=`expr $a + 1` | |
104 | .It | |
105 | The following example returns the filename portion of a pathname stored | |
106 | in variable a. The // characters act to eliminate ambiguity with the | |
107 | division operator. | |
108 | .Dl expr "//$a" Li : '.*/\e(.*\e)' | |
109 | .It | |
110 | The following example returns the number of characters in variable a. | |
111 | .Dl expr $a Li : '.*' | |
112 | .El | |
113 | .Sh DIAGNOSTICS | |
114 | The | |
115 | .Nm expr | |
116 | utility exits with one of the following values: | |
117 | .Bl -tag -width Ds | |
118 | .It 0 | |
119 | the expression is neither an empty string nor 0. | |
120 | .It 1 | |
121 | the expression is an empty string or 0. | |
122 | .It 2 | |
123 | the expression is invalid. | |
124 | .El | |
125 | .Sh STANDARDS | |
126 | The | |
127 | .Nm expr | |
128 | utility | |
129 | is expected to be | |
130 | .St -p1003.2 | |
131 | compatible. |