The meaning of the-Z to-D in the conditional judgment in the shell
Copyright Notice: This article original articles for bloggers, repost please indicate the source. If in doubt, please contact me. I'll be appreciated. https://blog.csdn.net/longyinyushi/article/details/50728049 https://blog.csdn.net/longyinyushi/article/details/50728049
The meaning of the-Z to-D in the conditional judgment in the shell
[-A file] if FILE existence is true.
[-B-file] True if file exists and is a block-specific file.
[-C file] is true if file exists and is a word special file.
[-D file] is true if FILE exists and is a directory.
[-e-file] is true if FILE exists.
[-F file] is true if file exists and is a normal file.
[-G file] True if FILE exists and Sgid is already set.
[-H file] True if FILE exists and is a symbolic connection.
[-K-file] True if file exists and a sticky bit has been set.
[-P file] If FILE exists and is a name pipe (f if O) true.
[-R File] True if FILE exists and is readable.
[-S file] If FILE exists and the size is not 0 true.
[-T FD] true if the file descriptor FD is open and points to a terminal.
[-U FILE] true if FILE exists and suid (set user ID) is set.
[-W file] If file is true if file exists and is writable.
[-X file] True if FILE exists and is executable.
[-O FILE] is true if FILE exists and is a valid user ID.
[-G file] True if FILE exists and is a valid user group.
[-L file] true if FILE exists and is a symbolic connection.
[-N file] If FILE exists and has been mod if IED since it is last read is true.
[-S file] is true if FILE exists and is a socket.
[File1-nt FILE2] If FILE1 has been changed more recently than if File2,or FILE1 and exists FILE2 is true.
[File1-ot FILE2] True if FILE1 is older than FILE2, or 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 turned on.
[-Z STRING] The length of "STRING" is zero is true.
The length of [-N string] or [string] "string" is not 0 Non-zero is true.
[ARG1 OP ARG2] "OP" is one of-eq,-ne,-lt,-le,-gt Or-ge. These arithmetic binary operators return true if "ARG1" are equal to, not equal to, less than, less than or equal to, great Er than, or greater than or equal to "ARG2", respectively. "ARG1" and "ARG2" are integers.
Digital judgment
[$count-gt "1"] if $count greater than 1 is true
-GT Greater than
-lt less than
-ne is not equal to
-eq equals
-ge is greater than or equal to
-le less than or equal
[STRING1 = = STRING2] If 2 strings are the same. "=" May is used instead of "= =" for strict POSIX compliance is true.
[STRING1!= STRING2] True if the string is not equal.
[STRING1 < STRING2] if "STRING1" sorts before "STRING2" lexicographically in the current locale is true.
[STRING1 > STRING2] If "STRING1" sorts after "STRING2" lexicographically to the current locale is true.