A conditional expression is used with the [[(double bracket) compound command to test attributes of files and to compare strings. Word splitting and file name substitution are not performed on words appearing between [[ and ]](double brackets). Each expression is constructed from one or more of the following unary or binary expressions:
-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. |
Note: In each of the previous expressions, if the File variable is similar to /dev/fd/ n , where n is an integer, then the test is applied to the open file whose descriptor number is n.
You can construct a compound expression from these primitives by using any of the following expressions, listed in decreasing order of precedence:
(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. |