BSD 3 development
[unix-history] / usr / man / man1 / test.1
CommitLineData
697f1ee9
BJ
1.TH TEST 1
2.SH NAME
3test \- condition command
4.SH SYNOPSIS
5.B test
6expr
7.SH DESCRIPTION
8.I test
9evaluates the expression
10.IR expr ,
11and if its value is true then returns zero exit status; otherwise, a
12non zero exit status is returned.
13.I test
14returns a non zero exit if there are no arguments.
15.PP
16The following primitives are used to construct
17.IR expr .
18.TP 9n
19.BR \-r " file"
20true if the file exists and is readable.
21.TP
22.BR \-w " file"
23true if the file exists and is writable.
24.TP
25.BR \-f " file"
26true if the file exists and is not a directory.
27.TP
28.BR \-d " file"
29true if the file exists exists and is a directory.
30.TP
31.BR \-s " file"
32true if the file exists and has a size greater than zero.
33.TP
34.BR \-t " [ fildes ]"
35true if the open file whose file descriptor number is
36.I fildes
37(1 by default)
38is associated with a terminal device.
39.TP
40.BR \-z " s1"
41true if the length of string
42.I s1
43is zero.
44.TP
45.BR \-n " s1"
46true if the length of the string
47.I s1
48is nonzero.
49.TP
50.RB s1 " = " s2
51true
52if the strings
53.I s1
54and
55.I s2
56are equal.
57.TP
58.RB s1 " != " s2
59true
60if the strings
61.I s1
62and
63.I s2
64are not equal.
65.TP
66s1
67true if
68.I s1
69is not the null string.
70.TP
71.RB n1 " \-eq " n2
72true if the integers
73.I n1
74and
75.I n2
76are algebraically equal.
77Any of the comparisons
78.BR \-ne ,
79.BR \-gt ,
80.BR \-ge ,
81.BR \-lt ,
82or
83.BR \-le
84may be used in place of
85.BR \-eq .
86.PP
87These primaries may be combined with the
88following operators:
89.TP
90.B !
91unary negation operator
92.TP
93.B \-a
94binary
95.I and
96operator
97.TP
98.B \-o
99binary
100.I or
101operator
102.TP
103.BR "( " "expr" " )"
104parentheses for grouping.
105.PP
106.B \-a
107has higher precedence than
108.B \-o.
109Notice that all the operators and flags are separate
110arguments to
111.IR test .
112Notice also that parentheses are meaningful
113to the Shell and must be escaped.
114.SH "SEE ALSO"
115sh(1), find(1)