Commit | Line | Data |
---|---|---|
fb0e8371 KB |
1 | .\" Copyright (c) 1991, 1993 |
2 | .\" The Regents of the University of California. All rights reserved. | |
301e682c | 3 | .\" |
ae122740 KB |
4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" the Institute of Electrical and Electronics Engineers, Inc. | |
6 | .\" | |
394a7f3c CL |
7 | .\" %sccs.include.redist.roff% |
8 | .\" | |
fb0e8371 | 9 | .\" @(#)test.1 8.1 (Berkeley) %G% |
394a7f3c CL |
10 | .\" |
11 | .Dd | |
12 | .Dt TEST 1 | |
d652604b | 13 | .Os |
394a7f3c CL |
14 | .Sh NAME |
15 | .Nm test | |
16 | .Nd condition evaluation utility | |
17 | .Sh SYNOPSIS | |
18 | .Nm test | |
19 | .Ar expression | |
20 | .Sh DESCRIPTION | |
21 | The | |
22 | .Nm test | |
23 | utility evaluates the expression and, if it evaluates | |
24 | to true, returns a zero (true) exit status; otherwise | |
25 | it returns 1 (false). | |
26 | If there is no expression, test also | |
27 | returns 1 (false). | |
28 | .Pp | |
29 | All operators and flags are separate arguments to the | |
30 | .Nm test | |
31 | utility. | |
32 | .Pp | |
33 | The following primaries are used to construct expression: | |
34 | .Bl -tag -width Ar | |
35 | .It Fl b Ar file | |
36 | True if | |
37 | .Ar file | |
38 | exists and is a block special | |
39 | file. | |
40 | .It Fl c Ar file | |
41 | True if | |
42 | .Ar file | |
43 | exists and is a character | |
44 | special file. | |
45 | .It Fl d Ar file | |
46 | True if | |
47 | .Ar file | |
48 | exists and is a directory. | |
97ab719d EA |
49 | .It Fl e Ar file |
50 | True if | |
51 | .Ar file | |
52 | exists (regardless of type). | |
394a7f3c CL |
53 | .It Fl f Ar file |
54 | True if | |
55 | .Ar file | |
56 | exists and is a regular file. | |
57 | .It Fl g Ar file | |
58 | True if | |
59 | .Ar file | |
60 | exists and its set group ID flag | |
61 | is set. | |
fce331a7 KB |
62 | .It Fl h Ar file |
63 | True if | |
64 | .Ar file | |
65 | exists and is a symbolic link. | |
394a7f3c CL |
66 | .It Fl n Ar string |
67 | True if the length of | |
68 | .Ar string | |
301e682c | 69 | is nonzero. |
394a7f3c CL |
70 | .It Fl p Ar file |
71 | True if | |
72 | .Ar file | |
73 | is a named pipe | |
74 | .Po Tn FIFO Pc . | |
75 | .It Fl r Ar file | |
76 | True if | |
77 | .Ar file exists and is readable. | |
78 | .It Fl s Ar file | |
79 | True if | |
80 | .Ar file | |
81 | exists and has a size greater | |
82 | than zero. | |
83 | .It Fl t Ar [file_descriptor] | |
84 | True if the file whose file descriptor number | |
85 | is | |
86 | .Ar file_descriptor | |
87 | (default 1) is open and is | |
88 | associated with a terminal. | |
89 | .It Fl u Ar file | |
90 | True if | |
91 | .Ar file | |
92 | exists and its set user ID flag | |
93 | is set. | |
94 | .It Fl w Ar file | |
95 | True if | |
96 | .Ar file | |
97 | exists and is writable. | |
98 | True | |
99 | indicates only that the write flag is on. | |
100 | The file is not writable on a read-only file | |
101 | system even if this test indicates true. | |
102 | .It Fl x Ar file | |
103 | True if | |
104 | .Ar file | |
105 | exists and is executable. | |
106 | True | |
107 | indicates only that the execute flag is on. | |
108 | If | |
109 | .Ar file | |
110 | is a directory, true indicates that | |
111 | .Ar file | |
112 | can be searched. | |
113 | .It Fl z Ar string | |
114 | True if the length of | |
115 | .Ar string | |
116 | is zero. | |
117 | .It Ar string | |
118 | True if | |
119 | .Ar string | |
120 | is not the null | |
121 | string. | |
122 | .It Ar \&s\&1 Cm \&= Ar \&s\&2 | |
123 | True if the strings | |
124 | .Ar \&s\&1 | |
125 | and | |
126 | .Ar \&s\&2 | |
127 | are identical. | |
128 | .It Ar \&s\&1 Cm \&!= Ar \&s\&2 | |
129 | True if the strings | |
130 | .Ar \&s\&1 | |
131 | and | |
132 | .Ar \&s\&2 | |
133 | are not identical. | |
134 | .It Ar \&n\&1 Fl \&eq Ar \&n\&2 | |
135 | True if the integers | |
136 | .Ar \&n\&1 | |
301e682c | 137 | and |
394a7f3c CL |
138 | .Ar \&n\&2 |
139 | are algebraically | |
140 | equal. | |
141 | .It Ar \&n\&1 Fl \&ne Ar \&n\&2 | |
142 | True if the integers | |
143 | .Ar \&n\&1 | |
301e682c | 144 | and |
394a7f3c CL |
145 | .Ar \&n\&2 |
146 | are not | |
147 | algebraically equal. | |
148 | .It Ar \&n\&1 Fl \> Ar \&n\&2 | |
149 | True if the integer | |
150 | .Ar \&n\&1 | |
151 | is algebraically | |
152 | greater than the integer | |
153 | .Ar \&n\&2 . | |
154 | .It Ar \&n\&1 Fl \&ge Ar \&n\&2 | |
155 | True if the integer | |
156 | .Ar \&n\&1 | |
157 | is algebraically | |
158 | greater than or equal to the integer | |
159 | .Ar \&n\&2 . | |
160 | .It Ar \&n\&1 Fl \< Ar \&n\&2 | |
161 | True if the integer | |
162 | .Ar \&n\&1 | |
163 | is algebraically less | |
164 | than the integer | |
165 | .Ar \&n\&2 . | |
166 | .It Ar \&n\&1 Fl \&le Ar \&n\&2 | |
167 | True if the integer | |
168 | .Ar \&n\&1 | |
169 | is algebraically less | |
170 | than or equal to the integer | |
171 | .Ar \&n\&2 . | |
172 | .El | |
173 | .Pp | |
174 | These primaries can be combined with the following operators: | |
175 | .Bl -tag -width Ar | |
176 | .It Cm \&! Ar expression | |
177 | True if | |
178 | .Ar expression | |
179 | is false. | |
180 | .It Ar expression1 Fl a Ar expression2 | |
181 | True if both | |
182 | .Ar expression1 | |
301e682c | 183 | and |
394a7f3c CL |
184 | .Ar expression2 |
185 | are true. | |
186 | .It Ar expression1 Fl o Ar expression2 | |
187 | True if either | |
188 | .Ar expression1 | |
301e682c | 189 | or |
394a7f3c CL |
190 | .Ar expression2 |
191 | are true. | |
192 | .It Cm \&( Ns Ar expression Ns Cm \&) | |
193 | True if expression is true. | |
194 | .El | |
195 | .Pp | |
196 | The | |
197 | .Fl a | |
198 | operator has higher precedence than the | |
199 | .Fl o | |
200 | operator. | |
97ab719d EA |
201 | .Sh GRAMMAR AMBIGUITY |
202 | The | |
203 | .Nm test | |
204 | grammar is inherently ambiguous. In order to assure a degree of consistency, | |
205 | the cases described in the | |
206 | .St -p1003.2 , | |
207 | section D11.2/4.62.4, standard | |
208 | are evaluated consistently according to the rules specified in the | |
209 | standards document. All other cases are subject to the ambiguity in the | |
210 | command semantics. | |
211 | .Sh RETURN VALUES | |
394a7f3c CL |
212 | The |
213 | .Nm test | |
214 | utility exits with one of the following values: | |
215 | .Bl -tag -width Ds | |
216 | .It 0 | |
217 | expression evaluated to true. | |
218 | .It 1 | |
219 | expression evaluated to false or expression was | |
220 | missing. | |
221 | .It >1 | |
222 | An error occurred. | |
223 | .El | |
224 | .Sh STANDARDS | |
225 | The | |
226 | .Nm test | |
227 | function is expected to be | |
d652604b CL |
228 | .St -p1003.2 |
229 | compatible. |