1test(1B) SunOS/BSD Compatibility Package Commands test(1B)
2
3
4
6 test - condition evaluation command
7
9 /usr/ucb/test expression
10
11
12 expression
13
14
16 test evaluates the expression expression and, if its value is true,
17 sets 0 (true) exit status; otherwise, a non-zero (false) exit status
18 is set. test also sets a non-zero exit status if there are no argu‐
19 ments. When permissions are tested, the effective user ID of the
20 process is used.
21
22
23 All operators, flags, and brackets (brackets used as shown in the sec‐
24 ond SYNOPSIS line) must be separate arguments to the test command; nor‐
25 mally these items are separated by spaces.
26
28 Primitives
29 The following primitives are used to construct expression:
30
31 -r filename True if filename exists and is readable.
32
33
34 -w filename True if filename exists and is writable.
35
36
37 -x filename True if filename exists and is executable.
38
39
40 -f filename True if filename exists and is a regular file. Alterna‐
41 tively, if /usr/bin/sh users specify /usr/ucb before
42 /usr/bin in their PATH environment variable, then test
43 will return true if filename exists and is
44 (not−a−directory). This is also the default for
45 /usr/bin/csh users.
46
47
48 -d filename True if filename exists and is a directory.
49
50
51 -c filename True if filename exists and is a character special
52 file.
53
54
55 -b filename True if filename exists and is a block special file.
56
57
58 -p filename True if filename exists and is a named pipe (fifo).
59
60
61 -u filename True if filename exists and its set-user- ID bit is
62 set.
63
64
65 -g filename True if filename exists and its set-group- ID bit is
66 set.
67
68
69 -k filename True if filename exists and its sticky bit is set.
70
71
72 -s filename True if filename exists and has a size greater than
73 zero.
74
75
76 -t[ fildes ] True if the open file whose file descriptor number is
77 fildes (1 by default) is associated with a terminal
78 device.
79
80
81 -z s1 True if the length of string s1 is zero.
82
83
84 -n s1 True if the length of the string s1 is non-zero.
85
86
87 s1 = s2 True if strings s1 and s2 are identical.
88
89
90 s1 != s2 True if strings s1 and s2 are not identical.
91
92
93 s1 True if s1 is not the null string.
94
95
96 n1 −eq n2 True if the integers n1 and n2 are algebraically equal.
97 Any of the comparisons −ne, −gt, −ge, −lt, and −le may
98 be used in place of −eq.
99
100
101 Operators
102 These primaries may be combined with the following operators:
103
104 ! Unary negation operator.
105
106
107 -a Binary and operator.
108
109
110 -o Binary or operator (-a has higher precedence than -o).
111
112
113 (expression) Parentheses for grouping. Notice also that parentheses
114 are meaningful to the shell and, therefore, must be
115 quoted.
116
117
119 See attributes(5) for descriptions of the following attributes:
120
121
122
123
124 ┌─────────────────────────────┬─────────────────────────────┐
125 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
126 ├─────────────────────────────┼─────────────────────────────┤
127 │Availability │SUNWscpu │
128 └─────────────────────────────┴─────────────────────────────┘
129
131 find(1), sh(1), attributes(5)
132
134 The not−a−directory alternative to the -f option is a transition aid
135 for BSD applications and may not be supported in future releases.
136
137
138 If you test a file you own (the -r , -w , or -x tests), but the permis‐
139 sion tested does not have the owner bit set, a non-zero (false) exit
140 status will be returned even though the file may have the group or
141 other bit set for that permission. The correct exit status will be set
142 if you are super-user.
143
144
145 The = and != operators have a higher precedence than the -r through -n
146 operators, and = and != always expect arguments; therefore, = and !=
147 cannot be used with the -r through -n operators.
148
149
150 If more than one argument follows the -r through -n operators, only the
151 first argument is examined; the others are ignored, unless a -a or a -o
152 is the second argument.
153
154
155
156SunOS 5.11 1 Apr 1996 test(1B)