Analyzing conditions shell

if [-a file]
then 
   echo 'hello world'
fi

 

if [[-a file || -b file]]
then 
   echo 'hello world'
fi

 

  

 

 

[-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 True o. 
[-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] If "STRING1" sorts before "STRING2" lexicographically in the current locale True. 
[STRING1> STRING2] If "STRING1" sorts after "STRING2" lexicographically in the current locale True.

[-Z "echo 111s | sed 's / [0-9] // g'"] && echo 1 || echo 0 # digital string are replaced


Guess you like

Origin www.cnblogs.com/weixuechao/p/12084312.html