[-A file] true if the file exists. [-B file] If the file exists and is a special block file, it is true. [-C file] If the file exists and is a special word file, it is true. [-D file] If the file exists and is a directory, it is true. [-E file] If the file exists, it is true. [-F file] If the file exists and is a normal file, it is true. [-G file] If the file exists and the sgid has been set, it is true. [-H file] If the file exists and is a symbolic connection, it is true. [-K file] true if the file exists and the stick bits have been set. [-P file] If the file exists and is a name pipe (f If O), it is true. [-R file] true if the file exists and is readable. [-S file] If the file exists and the size is not 0, it is true. [-T fd] It is true if the file descriptor FD is opened and points to a terminal. [-U file] If the file exists and SUID (Set User ID) is set, it is true. [-W file] true if the file exists and is writable. [-X file] true if the file exists and is executable. [-O file] true if the file exists and belongs to a valid user ID. [-G file] true if the file exists and belongs to a valid user group. [-L file] If the file exists and is a symbolic connection, it is true. [-N file] If file exists and has been mod, it is true if IED since it was last read. [-S file] If the file exists and is a socket, it is true. [File1-nt file2] If file1 has been changed more recently than file2, or if file1 exists and file2 does not is true. [File1-ot file2] True if file1 is older than file2, or if file2 exists and file1 does not exist. [File1-Ef file2] True if file1 and file2 point to the same device and node number. [-O optionname] true if the shell option "optionname" is enabled. [-Z string] "string" is true if its length is zero. If the length of [-N string] or [String] "string" is non-zero, it is true. [String1 = string2] If the two strings are the same. "=" May be used instead of "=" for strict POSIX compliance is true. [String1! = String2] true if the strings are not equal. [String1 <string2] True if "string1" sorts before "string2" lexicographically in the current locale. [String1> string2] True if "string1" sorts after "string2" lexicographically in the current locale. [Arg1 op arg2] "OP" is one of-EQ,-ne,-lt,-Le,-GT or-ge. these arithmetic binary operators return true if "arg1" is equal to, not equal to, less than, less than or equal to, greater than, or greater than or equal to "arg2 ", respectively. "arg1" and "arg2" are integers.
++ ++ ++
Operator |
Description |
Example |
File comparison operator |
-EFilename |
IfFilenameYes, true |
[-E/var/log/syslog] |
-DFilename |
IfFilenameIs a directory, it is true |
[-D/tmp/mydir] |
-FFilename |
IfFilenameIs a regular file, it is true |
[-F/usr/bin/grep] |
-LFilename |
IfFilenameIs a symbolic link, it is true |
[-L/usr/bin/grep] |
-RFilename |
IfFilenameReadable, true |
[-R/var/log/syslog] |
-WFilename |
IfFilenameWritable, true |
[-W/var/mytmp.txt] |
-XFilename |
IfFilenameExecutable, true |
[-L/usr/bin/grep] |
Filename1-NTFilename2 |
IfFilename1RatioFilename2New, true |
[/Tmp/install/etc/services-nt/etc/services] |
Filename1-OtFilename2 |
IfFilename1RatioFilename2Old, true |
[/Boot/bzimage-ot ARCH/i386/boot/bzimage] |
String comparison operator(Please pay attention to the use of quotation marks. This is a good way to prevent space from disturbing the code) |
-ZString |
IfStringIf the length is zero, it is true. |
[-Z $ myvar] |
-NString |
IfStringNon-zero length, true |
[-N $ myvar] |
String1=String2 |
IfString1AndString2Same, true |
[$ Myvar = One Two Three] |
String1! =String2 |
IfString1AndString2Otherwise, true |
[$ Myvar! = One Two Three] |
Arithmetic comparison operator |
Num1-EQNum2 |
Equal |
[3-EQ $ mynum] |
Num1-NeNum2 |
Not equal |
[3-ne $ mynum] |
Num1-LtNum2 |
Less |
[3-lt $ mynum] |
Num1-LeNum2 |
Less than or equal |
[3-Le $ mynum] |
Num1-GTNum2 |
Greater |
[3-GT $ mynum] |
Num1-GeNum2 |
Greater than or equal |
[3-ge $ mynum] |