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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值