#!/bin/bash
file="./var.sh"
if [ -r $file ]
then
echo "can read"
else
echo "can not read"
fi
if [ -w $file ]
then
echo "can write"
else
echo "can not write"
fi
if [ -x $file ]
then
echo "can exec"
else
echo "can not exec"
fi
if [ -f $file ]
then
echo "common file"
else
echo "special file"
fi
if [ -d $file ]
then
echo "is dir"
else
echo "is not dir"
fi
if [ -e $file ]
then
echo "file exist"
else
echo "file not exist"
fi
if [ -s $file ]
then
echo "file is not empty"
else
echo "file not exist"
fi
输出结果:
can read
can write
can not exec
common file
is not dir
file exist
file is not empty