Commit | Line | Data |
---|---|---|
394a7f3c CL |
1 | .\" Copyright (c) 1991 Regents of the University of California. |
2 | .\" 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 | .\" | |
97ab719d | 9 | .\" @(#)test.1 6.6 (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. | |
62 | .It Fl n Ar string | |
63 | True if the length of | |
64 | .Ar string | |
301e682c | 65 | is nonzero. |
394a7f3c CL |
66 | .It Fl p Ar file |
67 | True if | |
68 | .Ar file | |
69 | is a named pipe | |
70 | .Po Tn FIFO Pc . | |
71 | .It Fl r Ar file | |
72 | True if | |
73 | .Ar file exists and is readable. | |
74 | .It Fl s Ar file | |
75 | True if | |
76 | .Ar file | |
77 | exists and has a size greater | |
78 | than zero. | |
79 | .It Fl t Ar [file_descriptor] | |
80 | True if the file whose file descriptor number | |
81 | is | |
82 | .Ar file_descriptor | |
83 | (default 1) is open and is | |
84 | associated with a terminal. | |
85 | .It Fl u Ar file | |
86 | True if | |
87 | .Ar file | |
88 | exists and its set user ID flag | |
89 | is set. | |
90 | .It Fl w Ar file | |
91 | True if | |
92 | .Ar file | |
93 | exists and is writable. | |
94 | True | |
95 | indicates only that the write flag is on. | |
96 | The file is not writable on a read-only file | |
97 | system even if this test indicates true. | |
98 | .It Fl x Ar file | |
99 | True if | |
100 | .Ar file | |
101 | exists and is executable. | |
102 | True | |
103 | indicates only that the execute flag is on. | |
104 | If | |
105 | .Ar file | |
106 | is a directory, true indicates that | |
107 | .Ar file | |
108 | can be searched. | |
109 | .It Fl z Ar string | |
110 | True if the length of | |
111 | .Ar string | |
112 | is zero. | |
113 | .It Ar string | |
114 | True if | |
115 | .Ar string | |
116 | is not the null | |
117 | string. | |
118 | .It Ar \&s\&1 Cm \&= Ar \&s\&2 | |
119 | True if the strings | |
120 | .Ar \&s\&1 | |
121 | and | |
122 | .Ar \&s\&2 | |
123 | are identical. | |
124 | .It Ar \&s\&1 Cm \&!= Ar \&s\&2 | |
125 | True if the strings | |
126 | .Ar \&s\&1 | |
127 | and | |
128 | .Ar \&s\&2 | |
129 | are not identical. | |
130 | .It Ar \&n\&1 Fl \&eq Ar \&n\&2 | |
131 | True if the integers | |
132 | .Ar \&n\&1 | |
301e682c | 133 | and |
394a7f3c CL |
134 | .Ar \&n\&2 |
135 | are algebraically | |
136 | equal. | |
137 | .It Ar \&n\&1 Fl \&ne Ar \&n\&2 | |
138 | True if the integers | |
139 | .Ar \&n\&1 | |
301e682c | 140 | and |
394a7f3c CL |
141 | .Ar \&n\&2 |
142 | are not | |
143 | algebraically equal. | |
144 | .It Ar \&n\&1 Fl \> Ar \&n\&2 | |
145 | True if the integer | |
146 | .Ar \&n\&1 | |
147 | is algebraically | |
148 | greater than the integer | |
149 | .Ar \&n\&2 . | |
150 | .It Ar \&n\&1 Fl \&ge Ar \&n\&2 | |
151 | True if the integer | |
152 | .Ar \&n\&1 | |
153 | is algebraically | |
154 | greater than or equal to the integer | |
155 | .Ar \&n\&2 . | |
156 | .It Ar \&n\&1 Fl \< Ar \&n\&2 | |
157 | True if the integer | |
158 | .Ar \&n\&1 | |
159 | is algebraically less | |
160 | than the integer | |
161 | .Ar \&n\&2 . | |
162 | .It Ar \&n\&1 Fl \&le Ar \&n\&2 | |
163 | True if the integer | |
164 | .Ar \&n\&1 | |
165 | is algebraically less | |
166 | than or equal to the integer | |
167 | .Ar \&n\&2 . | |
168 | .El | |
169 | .Pp | |
170 | These primaries can be combined with the following operators: | |
171 | .Bl -tag -width Ar | |
172 | .It Cm \&! Ar expression | |
173 | True if | |
174 | .Ar expression | |
175 | is false. | |
176 | .It Ar expression1 Fl a Ar expression2 | |
177 | True if both | |
178 | .Ar expression1 | |
301e682c | 179 | and |
394a7f3c CL |
180 | .Ar expression2 |
181 | are true. | |
182 | .It Ar expression1 Fl o Ar expression2 | |
183 | True if either | |
184 | .Ar expression1 | |
301e682c | 185 | or |
394a7f3c CL |
186 | .Ar expression2 |
187 | are true. | |
188 | .It Cm \&( Ns Ar expression Ns Cm \&) | |
189 | True if expression is true. | |
190 | .El | |
191 | .Pp | |
192 | The | |
193 | .Fl a | |
194 | operator has higher precedence than the | |
195 | .Fl o | |
196 | operator. | |
97ab719d EA |
197 | .Sh GRAMMAR AMBIGUITY |
198 | The | |
199 | .Nm test | |
200 | grammar is inherently ambiguous. In order to assure a degree of consistency, | |
201 | the cases described in the | |
202 | .St -p1003.2 , | |
203 | section D11.2/4.62.4, standard | |
204 | are evaluated consistently according to the rules specified in the | |
205 | standards document. All other cases are subject to the ambiguity in the | |
206 | command semantics. | |
207 | .Sh RETURN VALUES | |
394a7f3c CL |
208 | The |
209 | .Nm test | |
210 | utility exits with one of the following values: | |
211 | .Bl -tag -width Ds | |
212 | .It 0 | |
213 | expression evaluated to true. | |
214 | .It 1 | |
215 | expression evaluated to false or expression was | |
216 | missing. | |
217 | .It >1 | |
218 | An error occurred. | |
219 | .El | |
220 | .Sh STANDARDS | |
221 | The | |
222 | .Nm test | |
223 | function is expected to be | |
d652604b CL |
224 | .St -p1003.2 |
225 | compatible. |