if语句之文件表达式

if语句之文件表达式

if [ -f  file ]    如果文件存在

if [ -d ...   ]    如果目录存在

if [ -s file  ]    如果文件存在且非空

if [ -r file  ]    如果文件存在且可读

if [ -w file  ]    如果文件存在且可写

if [ -x file  ]    如果文件存在且可执行

Notes:

= 作为等于时,其两边都必须加空格,否则失效。等号也是操作符,必须和其他变量,关键字,用空格格开

=,等号做赋值号时正好相反,两边不能有空格。

原文:

http://woshiyouyouchen.blog.163.com/blog/static/103998942011410101617365/

原文地址:https://www.cnblogs.com/mydomain/p/2700969.html