home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


Learning the Korn Shell

Learning the Korn ShellSearch this book
Previous: B.3 Built-in Shell Variables Appendix B
Reference Lists
Next: B.5 Options
 

B.4 Test Operators

These are the operators that are used with the [[ ...]] construct. They can be logically combined with && ("and") and || ("or") and grouped with parenthesis.

Operator True If...
-a file file exists.
-b file file is a block device file.
-c file file is a character device file.
-d file file is a directory.
-f file file is a regular file.
-g file file has its setgid bit set.
-k file file has its sticky bit set.
-n string string is non-null.
-o option option is set.
-p file file is a pipe or named pipe (FIFO file).
-r file file is readable.
-s file file is not empty.
-t N File descriptor N points to a terminal.
-u file file has its setuid bit set.
-w file file is writeable.
-x file

file is executable, or file is a directory that can be searched.

-z string string is null.
-G file file 's group ID is the same as that of the shell.
-L file file is a symbolic link.
-O file file is owned by the shell's user ID.
-S file file is a socket.
fileA -nt fileB fileA is newer than fileB .
fileA -ot fileB fileA is older than fileB .
fileA -ef fileB

fileA and fileB point to the same file.

string = pattern

string matches pattern (which can contain wildcards).

string != pattern string does not match pattern .
stringA < stringB

stringA comes before stringB in dictionary order.

stringA > stringB

stringA comes after stringB in dictionary order.

exprA -eq exprB

Arithmetic expressions exprA and exprB are equal.

exprA -ne exprB

Arithmetic expressions exprA and exprB are not equal.

exprA -lt exprB exprA is less than exprB .
exprA -gt exprB exprA is greater than exprB .
exprA -le exprB exprA is less than or equal to exprB .
exprA -ge exprB exprA is greater than or equal to exprB .


Previous: B.3 Built-in Shell Variables Learning the Korn Shell Next: B.5 Options
B.3 Built-in Shell Variables Book Index B.5 Options

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System