testconditionor[condition]
Evaluate a condition and, if its value is true, return a zero
exit status; otherwise, return a non-zero exit status.
An alternate form of the command uses [ ] rather than the word
test. The Korn shell allows an additional form, [[ ]].
condition is constructed using the expressions below. Conditions
are true if the description holds true. Features that are
Korn-shell-specific are marked with a (K).
filefile exists. (K)
filefile exists and is a block special file.
filefile exists and is a character special file.
filefile exists and is a directory.
filefile exists and is a regular file.
filefile exists and its group is the effective group ID. (K)
filefile exists and its set-group-id bit is set.
filefile exists and its sticky bit is set.
filefile exists and is a symbolic link. (K)
filefile exists and its owner is the effective user ID. (K)
cOption c is on. (K)
filefile exists and is a named pipe (fifo).
filefile exists and is readable.
filefile exists and is a socket. (K)
filefile exists and has a size greater than zero.
n]The open file descriptor n is associated with a terminal device;
default n is 1.
filefile exists and its set-user-id bit is set.
filefile exists and is writable.
filefile exists and is executable.
f1 -ef f2Files f1 and f2 are linked (refer to same file). (K)
f1 -nt f2File f1 is newer than f2. (K)
f1 -ot f2File f1 is older than f2. (K)
s1String s1 has non-zero length.
s1String s1 has zero length.
s1 = s2Strings s1 and s2 are identical.
In the Korn shell, s2 can be a regular expression.
s1 != s2Strings s1 and s2 are not identical.
In the Korn shell, s2 can be a regular expression.
s1 < s2ASCII value of s1 precedes that of s2.
(Valid only within [[ ]] construct). (K)
s1 > s2ASCII value of s1 follows that of s2.
(Valid only within [[ ]] construct). (K)
stringstring is not null.
n1 -eq n2n1 equals n2.
n1 -ge n2n1 is greater than or equal to n2.
n1 -gt n2n1 is greater than n2.
n1 -le n2n1 is less than or equal to n2.
n1 -lt n2n1 is less than n2.
n1 -ne n2n1 does not equal n2.
condition)True if condition is true (used for grouping).
The ( )'s should be preceded by a \.
True if condition is false.
condition1True if both conditions are true.
condition1True if both conditions are true. (Valid only within [[ ]] construct.) (K)
condition1True if either condition is true.
condition1True if either condition is true. (Valid only within [[ ]] construct.) (K)
Each example below shows the first line of various statements that might use a test condition:
while test $# -gt 0 While there are arguments ... while [ -n "$1" ] While there are nonempty arguments ... if [ $count -lt 10 ] If$countis less than 10 ... if [ -d RCS ] If the RCS directory exists ... if [ "$answer" != "y" ] If the answer is noty... if [ ! -r "$1" -o ! -f "$1" ] If the first argument is not a readable file or a regular file ...