Korn Shell: Unix and Linux Programming Manual, Third Edition, The By Anatole Olczak
Table of Contents
Appendix G. Pdksh Quick Reference
The [[...]] command is used to evaluate conditional expressions with file attributes, strings, and integers. The basic format is:
[[expression]]
where expression is the condition you are evaluating. There must be whitespace after the opening brackets, and before the closing brackets. Whitespace must also separate the expression arguments and operators. If the expression evaluates to true, then a zero exit status is returned, otherwise the expression evaluates to false and a non-zero exit status is returned.
[[...]] String Operators
nstring
true if length of string is not zero
ooption
true if option is set
zstring
true if length of string is zero
string1 = string2
true if string1 is equal to string2
string1 != string2
true if string1 is not equal to string2
string = pattern
true if string matches pattern
string != pattern
true if string does not match pattern
string1 < string2
true if string1 is less than string2
string1 > string2
true if string1 is greater than string2
[[...]] File Operators
afile
true if file exists
bfile
true if file exists and is a block special file
cfile
true if file exists and is a character special file
dfile
true if file exists and is a directory
ffile
true if file exists is a regular file
gfile
true if file exists and its setgid bit is set
Gfile
true if file exists and its group id matches the current effective group id
kfile
true if file exists and its sticky bit is set
Lfile
true if file exists and is a symbolic link
Ofile
true if file exists and is owned by the effective user id
pfile
true if file exists and is a fifo special file or a pipe
rfile
true if file exists and is readable
sfile
true if file exists and its size is greater than zero
Sfile
true if file exists and is a socket
tn
true if file descriptor n is open and associated with a terminal device
ufile
true if file exists and its set user-id bit is set
wfile
true if file exists and is writable
xfile
true if file exists and is executable. If file is a directory, then true indicates that the directory is readable.
file1 effile2
true if file1 and file2 exist and refer to same file