shell (7) if the expression

Expressions file
if [-f file] If the file exists
if [-d ...] if the directory exists
if [-s file] if the file exists and is non-empty
if [-r file] if the file exists and is readable
if [-w file ] If the file exists and is writable
if [-x file] if the file exists and is executable

Expression integer variables
if [int1 -eq int2] If int1 equal INT2
IF [int1 -ne INT2] if not equal
if [int1 -ge int2] If> =
IF [-gt INT2 int1] If>
IF [int1 -le INT2 ] If <=
IF [-LT-INT1 INT2] If <

Variable expression string
If [$ a = $ b] If string1 equals string2
string allows the use of an assignment do equate
if [$ string1! = $ String2 ] If not equal string1 string2
IF [-n $ string] If a non-string empty (non-zero), and returns 0 (to true)
IF [$ string the -Z] If the string is empty
if [$ sting] If a non-null string, returns 0 (-n and the like)

s h e l l in the conditions of judgment i f - z to - d is intended Si
[-a FILE] If FILE true existence.
[-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.

Guess you like

Origin www.cnblogs.com/lovychen/p/11225241.html