Commit | Line | Data |
---|---|---|
ca9c5933 AM |
1 | .\" Copyright (c) 1991 Regents of the University of California. |
2 | .\" All rights reserved. | |
3 | .\" | |
4 | .\" This code is derived from software contributed to Berkeley by | |
5 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
6 | .\" | |
7 | .\" Redistribution and use in source and binary forms, with or without | |
8 | .\" modification, are permitted provided that the following conditions | |
9 | .\" are met: | |
10 | .\" 1. Redistributions of source code must retain the above copyright | |
11 | .\" notice, this list of conditions and the following disclaimer. | |
12 | .\" 2. 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 | .\" 3. All advertising materials mentioning features or use of this software | |
16 | .\" must display the following acknowledgement: | |
17 | .\" This product includes software developed by the University of | |
18 | .\" California, Berkeley and its contributors. | |
19 | .\" 4. Neither the name of the University nor the names of its contributors | |
20 | .\" may be used to endorse or promote products derived from this software | |
21 | .\" without specific prior written permission. | |
22 | .\" | |
23 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
24 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
25 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
26 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
27 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
28 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
29 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
30 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
31 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
32 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
33 | .\" SUCH DAMAGE. | |
34 | .\" | |
35 | .\" @(#)test.1 6.6 (Berkeley) 6/8/92 | |
36 | .\" | |
37 | .Dd June 8, 1992 | |
38 | .Dt TEST 1 | |
39 | .Os | |
40 | .Sh NAME | |
41 | .Nm test | |
42 | .Nd Condition evaluation utility. | |
43 | .Sh SYNOPSIS | |
44 | .Nm test | |
45 | .Ar expression | |
46 | .Sh DESCRIPTION | |
47 | The | |
48 | .Nm test | |
49 | utility evaluates the expression and, if it evaluates | |
50 | to true, returns a zero (true) exit status; otherwise | |
51 | it returns 1 (false). | |
52 | If there is no expression, test also | |
53 | returns 1 (false). | |
54 | .Pp | |
55 | All operators and flags are separate arguments to the | |
56 | .Nm test | |
57 | utility. | |
58 | .Pp | |
59 | The following primaries are used to construct expression: | |
60 | .Bl -tag -width Ar | |
61 | .It Fl b Ar file | |
62 | True if | |
63 | .Ar file | |
64 | exists and is a block special | |
65 | file. | |
66 | .It Fl c Ar file | |
67 | True if | |
68 | .Ar file | |
69 | exists and is a character | |
70 | special file. | |
71 | .It Fl d Ar file | |
72 | True if | |
73 | .Ar file | |
74 | exists and is a directory. | |
75 | .It Fl e Ar file | |
76 | True if | |
77 | .Ar file | |
78 | exists (regardless of type). | |
79 | .It Fl f Ar file | |
80 | True if | |
81 | .Ar file | |
82 | exists and is a regular file. | |
83 | .It Fl g Ar file | |
84 | True if | |
85 | .Ar file | |
86 | exists and its set group ID flag | |
87 | is set. | |
88 | .It Fl n Ar string | |
89 | True if the length of | |
90 | .Ar string | |
91 | is nonzero. | |
92 | .It Fl p Ar file | |
93 | True if | |
94 | .Ar file | |
95 | is a named pipe | |
96 | .Po Tn FIFO Pc . | |
97 | .It Fl r Ar file | |
98 | True if | |
99 | .Ar file exists and is readable. | |
100 | .It Fl s Ar file | |
101 | True if | |
102 | .Ar file | |
103 | exists and has a size greater | |
104 | than zero. | |
105 | .It Fl t Ar [file_descriptor] | |
106 | True if the file whose file descriptor number | |
107 | is | |
108 | .Ar file_descriptor | |
109 | (default 1) is open and is | |
110 | associated with a terminal. | |
111 | .It Fl u Ar file | |
112 | True if | |
113 | .Ar file | |
114 | exists and its set user ID flag | |
115 | is set. | |
116 | .It Fl w Ar file | |
117 | True if | |
118 | .Ar file | |
119 | exists and is writable. | |
120 | True | |
121 | indicates only that the write flag is on. | |
122 | The file is not writable on a read-only file | |
123 | system even if this test indicates true. | |
124 | .It Fl x Ar file | |
125 | True if | |
126 | .Ar file | |
127 | exists and is executable. | |
128 | True | |
129 | indicates only that the execute flag is on. | |
130 | If | |
131 | .Ar file | |
132 | is a directory, true indicates that | |
133 | .Ar file | |
134 | can be searched. | |
135 | .It Fl z Ar string | |
136 | True if the length of | |
137 | .Ar string | |
138 | is zero. | |
139 | .It Ar string | |
140 | True if | |
141 | .Ar string | |
142 | is not the null | |
143 | string. | |
144 | .It Ar \&s\&1 Cm \&= Ar \&s\&2 | |
145 | True if the strings | |
146 | .Ar \&s\&1 | |
147 | and | |
148 | .Ar \&s\&2 | |
149 | are identical. | |
150 | .It Ar \&s\&1 Cm \&!= Ar \&s\&2 | |
151 | True if the strings | |
152 | .Ar \&s\&1 | |
153 | and | |
154 | .Ar \&s\&2 | |
155 | are not identical. | |
156 | .It Ar \&n\&1 Fl \&eq Ar \&n\&2 | |
157 | True if the integers | |
158 | .Ar \&n\&1 | |
159 | and | |
160 | .Ar \&n\&2 | |
161 | are algebraically | |
162 | equal. | |
163 | .It Ar \&n\&1 Fl \&ne Ar \&n\&2 | |
164 | True if the integers | |
165 | .Ar \&n\&1 | |
166 | and | |
167 | .Ar \&n\&2 | |
168 | are not | |
169 | algebraically equal. | |
170 | .It Ar \&n\&1 Fl \> Ar \&n\&2 | |
171 | True if the integer | |
172 | .Ar \&n\&1 | |
173 | is algebraically | |
174 | greater than the integer | |
175 | .Ar \&n\&2 . | |
176 | .It Ar \&n\&1 Fl \&ge Ar \&n\&2 | |
177 | True if the integer | |
178 | .Ar \&n\&1 | |
179 | is algebraically | |
180 | greater than or equal to the integer | |
181 | .Ar \&n\&2 . | |
182 | .It Ar \&n\&1 Fl \< Ar \&n\&2 | |
183 | True if the integer | |
184 | .Ar \&n\&1 | |
185 | is algebraically less | |
186 | than the integer | |
187 | .Ar \&n\&2 . | |
188 | .It Ar \&n\&1 Fl \&le Ar \&n\&2 | |
189 | True if the integer | |
190 | .Ar \&n\&1 | |
191 | is algebraically less | |
192 | than or equal to the integer | |
193 | .Ar \&n\&2 . | |
194 | .El | |
195 | .Pp | |
196 | These primaries can be combined with the following operators: | |
197 | .Bl -tag -width Ar | |
198 | .It Cm \&! Ar expression | |
199 | True if | |
200 | .Ar expression | |
201 | is false. | |
202 | .It Ar expression1 Fl a Ar expression2 | |
203 | True if both | |
204 | .Ar expression1 | |
205 | and | |
206 | .Ar expression2 | |
207 | are true. | |
208 | .It Ar expression1 Fl o Ar expression2 | |
209 | True if either | |
210 | .Ar expression1 | |
211 | or | |
212 | .Ar expression2 | |
213 | are true. | |
214 | .It Cm \&( Ns Ar expression Ns Cm \&) | |
215 | True if expression is true. | |
216 | .El | |
217 | .Pp | |
218 | The | |
219 | .Fl a | |
220 | operator has higher precedence than the | |
221 | .Fl o | |
222 | operator. | |
223 | .Sh GRAMMAR AMBIGUITY | |
224 | The | |
225 | .Nm test | |
226 | grammar is inherently ambiguous. In order to assure a degree of consistency, | |
227 | the cases described in the | |
228 | .St -p1003.2 , | |
229 | section D11.2/4.62.4, standard | |
230 | are evaluated consistently according to the rules specified in the | |
231 | standards document. All other cases are subject to the ambiguity in the | |
232 | command semantics. | |
233 | .Sh RETURN VALUES | |
234 | The | |
235 | .Nm test | |
236 | utility exits with one of the following values: | |
237 | .Bl -tag -width Ds | |
238 | .It 0 | |
239 | expression evaluated to true. | |
240 | .It 1 | |
241 | expression evaluated to false or expression was | |
242 | missing. | |
243 | .It >1 | |
244 | An error occurred. | |
245 | .El | |
246 | .Sh STANDARDS | |
247 | The | |
248 | .Nm test | |
249 | function is expected to be | |
250 | .St -p1003.2 | |
251 | compatible. |