SHELL IF determination condition, the determination condition

 

Analyzing a string

str1 = str2 when two strings with the same contents, the length of real
str1! = Str2 str1 and str2 string when unequal true when
-n str1 string when the length is greater than 0 is true (non-empty string)
when the -Z str1 true length of the string (the empty string) is 0
str1 str1 non-empty string when true

second digital determination

int1 -eq int2 two real numbers are equal to
unequal int1 -ne int2 two atoms true
int1 -gt int2 int1 is greater than int2 true
int1 -ge int2 int1 int2 greater than or equal to true
int1 -lt int2 int1 int2 less than true
int1 -le int2 int1 int2 less true

determination document 3

-r file true user-readable
- w file the user can write is true
-x file users can perform true
-f file file as a regular file is true
for the directory file -d file true
-c file file is a character special file is true
-b file file to block special file true
-s file when the file size of the non-0 is true
when -t file if the file descriptor (default 1) to the terminal device as the true

3 complex logic Analyzing

-a and
-o or
! non

 

[-A FILE] True if FILE exists.
[-B FILE] If FILE exists and is a block special file True.
[-C FILE] If FILE exists and is a character special file True.
[-D FILE] If FILE exists and is a directory True.
[-E FILE] True if FILE exists.
[-F FILE] If FILE exists and is a regular file True.
[-G FILE] If FILE exists and has been set SGID True. [-H FILE] If FILE exists and is a symbolic link True.
[-K FILE] If FILE exists and made sticky bit has been set True.
[-P FILE] If FILE exists and is a named pipe (F if O) True.
[-R & lt FILE] If FILE exists and is readable True.
[-S FILE] FILE exists and if the size is not 0 True.
[-T FD] If the file descriptor FD is open and refers to a terminal True.
[-U FILE] FILE exists and if the SUID (set user ID) True.
[-W FILE] If FILE if FILE exists and is writable True.
[-X FILE] If FILE exists and is executable True.
[-O FILE] FILE exists and if the user ID is valid True.
[-G FILE] If FILE exists and is a valid user group True.
[-L FILE] If FILE exists and is a symbolic link True.
[-N FILE] If FILE exists and has been mod if ied since it was last read was true.
[-S FILE] If FILE exists and is a socket True.
[FILE1 -nt FILE2] if FILE1 has been changed more recently than FILE2 , or if FILE1 exists and FILE2 does not True.
[FILE1 -ot FILE2] True if FILE1 is older than FILE2, or FILE2 exists and FILE1 True does not exist.
[FILE1 -ef FILE2] If the same FILE1 and FILE2 pointing device and inode numbers True.
[-O OPTIONNAME] If the shell option "OPTIONNAME" True open.
[-Z STRING] length "STRING" True zero.
Length [-n STRING] or [STRING] "STRING" is non-zero non-zero True.
[STRING1 == STRING2] If the same two strings. "=" May be used instead of "==" for strict POSIX compliance True.
[STRING1! = STRING2] True if the strings are not equal.
[ STRING1 < STRING2 ]  如果 “STRING1” sorts before “STRING2” lexicographically in the current locale则为真。
[ STRING1 > STRING2 ]  如果 “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.

Guess you like

Origin www.cnblogs.com/tingxin/p/12210821.html