Remove type cast for fillw's second arg; it messed up the pointer arith
[unix-history] / bin / test / test.1
CommitLineData
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
47The
48.Nm test
49utility evaluates the expression and, if it evaluates
50to true, returns a zero (true) exit status; otherwise
51it returns 1 (false).
52If there is no expression, test also
53returns 1 (false).
54.Pp
55All operators and flags are separate arguments to the
56.Nm test
57utility.
58.Pp
59The following primaries are used to construct expression:
60.Bl -tag -width Ar
61.It Fl b Ar file
62True if
63.Ar file
64exists and is a block special
65file.
66.It Fl c Ar file
67True if
68.Ar file
69exists and is a character
70special file.
71.It Fl d Ar file
72True if
73.Ar file
74exists and is a directory.
75.It Fl e Ar file
76True if
77.Ar file
78exists (regardless of type).
79.It Fl f Ar file
80True if
81.Ar file
82exists and is a regular file.
83.It Fl g Ar file
84True if
85.Ar file
86exists and its set group ID flag
87is set.
88.It Fl n Ar string
89True if the length of
90.Ar string
91is nonzero.
92.It Fl p Ar file
93True if
94.Ar file
95is a named pipe
96.Po Tn FIFO Pc .
97.It Fl r Ar file
98True if
99.Ar file exists and is readable.
100.It Fl s Ar file
101True if
102.Ar file
103exists and has a size greater
104than zero.
105.It Fl t Ar [file_descriptor]
106True if the file whose file descriptor number
107is
108.Ar file_descriptor
109(default 1) is open and is
110associated with a terminal.
111.It Fl u Ar file
112True if
113.Ar file
114exists and its set user ID flag
115is set.
116.It Fl w Ar file
117True if
118.Ar file
119exists and is writable.
120True
121indicates only that the write flag is on.
122The file is not writable on a read-only file
123system even if this test indicates true.
124.It Fl x Ar file
125True if
126.Ar file
127exists and is executable.
128True
129indicates only that the execute flag is on.
130If
131.Ar file
132is a directory, true indicates that
133.Ar file
134can be searched.
135.It Fl z Ar string
136True if the length of
137.Ar string
138is zero.
139.It Ar string
140True if
141.Ar string
142is not the null
143string.
144.It Ar \&s\&1 Cm \&= Ar \&s\&2
145True if the strings
146.Ar \&s\&1
147and
148.Ar \&s\&2
149are identical.
150.It Ar \&s\&1 Cm \&!= Ar \&s\&2
151True if the strings
152.Ar \&s\&1
153and
154.Ar \&s\&2
155are not identical.
156.It Ar \&n\&1 Fl \&eq Ar \&n\&2
157True if the integers
158.Ar \&n\&1
159and
160.Ar \&n\&2
161are algebraically
162equal.
163.It Ar \&n\&1 Fl \&ne Ar \&n\&2
164True if the integers
165.Ar \&n\&1
166and
167.Ar \&n\&2
168are not
169algebraically equal.
170.It Ar \&n\&1 Fl \&gt Ar \&n\&2
171True if the integer
172.Ar \&n\&1
173is algebraically
174greater than the integer
175.Ar \&n\&2 .
176.It Ar \&n\&1 Fl \&ge Ar \&n\&2
177True if the integer
178.Ar \&n\&1
179is algebraically
180greater than or equal to the integer
181.Ar \&n\&2 .
182.It Ar \&n\&1 Fl \&lt Ar \&n\&2
183True if the integer
184.Ar \&n\&1
185is algebraically less
186than the integer
187.Ar \&n\&2 .
188.It Ar \&n\&1 Fl \&le Ar \&n\&2
189True if the integer
190.Ar \&n\&1
191is algebraically less
192than or equal to the integer
193.Ar \&n\&2 .
194.El
195.Pp
196These primaries can be combined with the following operators:
197.Bl -tag -width Ar
198.It Cm \&! Ar expression
199True if
200.Ar expression
201is false.
202.It Ar expression1 Fl a Ar expression2
203True if both
204.Ar expression1
205and
206.Ar expression2
207are true.
208.It Ar expression1 Fl o Ar expression2
209True if either
210.Ar expression1
211or
212.Ar expression2
213are true.
214.It Cm \&( Ns Ar expression Ns Cm \&)
215True if expression is true.
216.El
217.Pp
218The
219.Fl a
220operator has higher precedence than the
221.Fl o
222operator.
223.Sh GRAMMAR AMBIGUITY
224The
225.Nm test
226grammar is inherently ambiguous. In order to assure a degree of consistency,
227the cases described in the
228.St -p1003.2 ,
229section D11.2/4.62.4, standard
230are evaluated consistently according to the rules specified in the
231standards document. All other cases are subject to the ambiguity in the
232command semantics.
233.Sh RETURN VALUES
234The
235.Nm test
236utility exits with one of the following values:
237.Bl -tag -width Ds
238.It 0
239expression evaluated to true.
240.It 1
241expression evaluated to false or expression was
242missing.
243.It >1
244An error occurred.
245.El
246.Sh STANDARDS
247The
248.Nm test
249function is expected to be
250.St -p1003.2
251compatible.