首先,判断一下,让使用者输入一个档名,我们判断:
- 这个文件是否存在,若不存在则给予一个『Filename does not exist』的信息,并中断程序;
- 若这个文件存在,则判断他是个文件或目录,结果输出『Filename is regular file』或 『Filename is directory』
- 判断一下,运行者的身份对这个文件或目录所拥有的权限,并输出权限数据!
#!/bin/bash
#User input a filename,programe will check the flowing:
# 1.)exist? 2.)file/directory? 3.)file permissions
echo -e "Please input a filename,I'll check the filename's type and its permissions.\n\n"
read -p "Please input a fliename:" filename
test -z $filename && echo "You must input a filename!Rember next time you mustn't input an empty file! " &