test命令-linux shell 脚本
程序员文章站
2022-03-16 11:47:15
#!/bin/bash # This is program will check you file name,which sys has or not,end print types. #2019/07/19 FSQ First release echo -e "input file name:" ......
#!/bin/bash
# this is program will check you file name,which sys has or not,end print types.
#2019/07/19 fsq
first release
echo -e "input file name:" filename
read filename
test -z $filename && echo "please input a file name" && exit 0 #test -z 检查输入是否为空
test ! -e $filename && echo" $filename is not exsit" && exit 0 # test -e 检查输入的文件是否存在
test -d $filename && filetype="regulare file" #检查文件的是否是目录
test -f $filename && filetype="directory" #检查文件是否常规文件
test -r $filename && perm="readable" #检查文件的执行状态 是否可读
test -w $filename && perm="$perm writeable" #检查文件的执行状态 是否可写
test -x $filename && perm="$perm execute#检查文件是否 可执行
echo "the file name : $filename is a $filetype" #输出文件的类型
echo "and the permissions are :$perm" #输出文件的权限