1test(1F) FMLI Commands test(1F)
2
3
4
6 test - condition evaluation command
7
9 test expression
10
11
12 expression
13
14
16 test evaluates the expression expression and if its value is true, sets
17 a 0 (TRUE) exit status; otherwise, a non-zero (FALSE) exit status is
18 set; test also sets a non-zero exit status if there are no arguments.
19 When permissions are tested, the effective user ID of the process is
20 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 test. Normally these
25 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.
41
42
43 -d filename True if filename exists and is a directory.
44
45
46 -c filename True if filename exists and is a character special
47 file.
48
49
50 -b filename True if filename exists and is a block special file.
51
52
53 -p filename True if filename exists and is a named pipe (FIFO).
54
55
56 -u filename True if filename exists and its set-user-ID bit is
57 set.
58
59
60 -g filename True if filename exists and its set-group-ID bit is
61 set.
62
63
64 -k filename True if filename exists and its sticky bit is set.
65
66
67 -s filename True if filename exists and has a size greater than
68 0.
69
70
71 -t[fildes] True if the open file whose file descriptor number is
72 fildes (1 by default) is associated with a terminal
73 device.
74
75
76 -z s1 True if the length of string s1 is 0.
77
78
79 -n s1 True if the length of the string s1 is non-zero.
80
81
82 s1 = s2 True if strings s1 and s2 are identical.
83
84
85 s1 != s2 True if strings s1 and s2 are not identical.
86
87
88 s1 True if s1 is not the null string.
89
90
91 n1 −eq n2 True if the integers n1 and n2 are algebraically
92 equal. Any of the comparisons −ne, −gt, −ge, −lt, and
93 −le may be used in place of −eq.
94
95
96 Operators
97 These primaries may be combined with the following operators:
98
99 ! Unary negation operator.
100
101
102 -a Binary and operator.
103
104
105 -o Binary or operator (-a has higher precedence than
106 -o).
107
108
109 `(expression)` Parentheses for grouping. Notice also that paren‐
110 theses are meaningful to the shell and, there‐
111 fore, must be quoted.
112
113
115 See attributes(5) for descriptions of the following attributes:
116
117
118
119
120 ┌─────────────────────────────┬─────────────────────────────┐
121 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
122 ├─────────────────────────────┼─────────────────────────────┤
123 │Availability │SUNWcsu │
124 └─────────────────────────────┴─────────────────────────────┘
125
127 find(1), sh(1), attributes(5)
128
130 If you test a file you own (the -r , -w , or -x tests), but the permis‐
131 sion tested does not have the owner bit set, a non-zero (false) exit
132 status will be returned even though the file may have the group or
133 other bit set for that permission. The correct exit status will be set
134 if you are super-user.
135
136
137 The = and != operators have a higher precedence than the -r through -n
138 operators, and = and != always expect arguments; therefore, = and !=
139 cannot be used with the -r through -n operators.
140
141
142 If more than one argument follows the -r through -n operators, only the
143 first argument is examined; the others are ignored, unless a -a or a -o
144 is the second argument.
145
146
147
148SunOS 5.11 5 Jul 1990 test(1F)