I write $SHELL scripts most days mostly Korn Shell, I am always looking these two tables up on other sites for the Korn shell rather than commit them to memory, so why not just post it here so I know where to find it forevermore. We mostly use ksh over bash as Korn shell is on every system regardless of the age of that host.
Korn Shell Operators
Item | Description |
-a File | True, if the specified file is a symbolic link that points to another file that does exist. |
-b File | True, if the specified file exists and is a block special file. |
-c File | True, if the specified file exists and is a character special file. |
-d File | True, if the specified file exists and is a directory. |
-e File | True, if the specified file exists. |
-f File | True, if the specified file exists and is an ordinary file. |
-g File | True, if the specified file exists and its setgid bit is set. |
-h File | True, if the specified file exists and is a symbolic link. |
-k File | True, if the specified file exists and its sticky bit is set. |
-n String | True, if the length of the specified string is nonzero. |
-o Option | True, if the specified option is on. |
-p File | True, if the specified file exists and is a FIFO special file or a pipe. |
-r File | True, if the specified file exists and is readable by the current process. |
-s File | True, if the specified file exists and has a size greater than 0. |
-t FileDescriptor | True, if specified file descriptor number is open and associated with a terminal device. |
-u File | True, if the specified file exists and its setuid bit is set. |
-w File | True, if the specified file exists and the write bit is on. However, the file will not be writable on a read-only file system even if this test indicates true. |
-x File | True, if the specified file exists and the execute flag is on. If the specified file exists and is a directory, then the current process has permission to search in the directory. |
-z String | True, if length of the specified string is 0. |
-L File | True, if the specified file exists and is a symbolic link. |
-O File | True, if the specified file exists and is owned by the effective user ID of this process. |
-G File | True, if the specified file exists and its group matches the effective group ID of this process. |
-S File | True, if the specified file exists and is a socket. |
File1 -nt File2 | True, if File1 exists and is newer than File2. |
File1 -ot File2 | True, if File1 exists and is older than File2. |
File1 -ef File2 | True, if File1 and File2 exist and refer to the same file. |
String1 = String2 | True, if String1 is equal to String2. |
String1 != String2 | True, if String1 is not equal to String2. |
String = Pattern | True, if the specified string matches the specified pattern. |
String != Pattern | True, if the specified string does not match the specified pattern. |
String1 < String2 | True, if String1 comes before String2 based on the ASCII value of their characters. |
String1 > String2 | True, if String1 comes after String2 based on the ASCII value of their characters. |
Expression1 -eq Expression2 | True, if Expression1 is equal to Expression2. |
Expression1 -ne Expression2 | True, if Expression1 is not equal to Expression2. |
Expression1 -lt Expression2 | True, if Expression1 is less than Expression2. |
Expression1 -gt Expression2 | True, if Expression1 is greater than Expression2. |
Expression1 -le Expression2 | True, if Expression1 is less than or equal to Expression2. |
Expression1 -ge Expression2 | True, if Expression1 is greater than or equal to Expression2. |
You can combine expressions together like below;
Item | Description |
(Expression) | True, if the specified expression is true. Used to group expressions. |
! Expression | True, if the specified expression is false. |
Expression1 && Expression2 | True, if Expression1 and Expression2 are both true. |
Expression1 || Expression2 | True, if either Expression1 or Expression2 is true. |
If you enjoyed this on post Korn Shell operators please see some of my others here.
Leave a Reply