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