shell脚本编程判断是文件或是目录以及文件权限的输出!

shell脚本编程判断是文件或是目录以及文件权限的输出!在终端下运行程序,首先清屏,然后提示:“Input a file or directory name, please!”。从键盘输入一个字符串(如:xxx),如果该字符串是目录,则显示:“xxx is a directory.”;如果该字符串是文件(如:xxx),则显示:“xxx is a regular file.”;如果该文件是可读的,则显示:“xxx is a readable file.”;如果该文件是可写的,则显示:“xxx is a writable.” 如果该文件是可执行的,则显示:“xxx is a executable.”;如果既不是目录也不是文件,则显示:“This script cannot get the file/directory xxx information!”。

代码如下:

clear
echo "Input a file or directory name,please!"
read str
if test -d $str
then
echo "$str is a directory."
elif test -f $str
then
echo "$str is a regular file."
else
echo "This script cannot get the file/directory $str information!"
fi
if test -r $str
then
echo "$str is a readable file."
fi
if test -w $str
then
echo "$str is a writable."
fi
if test -x $str
then
echo "$str is a executable."
fi

你可能感兴趣的:(shell脚本,Linux)