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