1、文件测试运算符
“-e file”:检测文件是否存在(包含了:目录和文件),如果是,返回true
file="hello.sh"
if [ -e $file ]
then
echo "文件存在"
else
echo "文件不存在"
fi
“-s file”:检测文件是否为空(文件有内容),如果是,那么返回true
file="hello.sh"
if [ -s $file ]
then
echo "文件有内容"
else
echo "文件没有内容"
fi
"-f file"检测一个文件是否是普通文件(既不是目录,也不是设备文件),如果是返回true
file="hello.sh"
if [ -f $file ]
then
echo "普通文件"
else
echo "系统文件"
fi
“-x file”:检测文件是否是可执行文件,如果是,那么返回true
file="hello.sh"
if [ -w $file ]
then
echo "可执行"
else
echo "不可执行"
fi
"-w file:检测文件是否可写,如果是返回true
file=