shell脚本之判断文件类型

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本之判断文件类型相关的知识,希望对你有一定的参考价值。

技术图片

判断文件类型
#!/bin/bash
read -p "Please input a  filename:" file
if [ -z "$file" ];then
                echo "Error,please input a filename"
        exit 1
elif [ ! -e "$file" ];then
        echo "Your input is not  exist"
        exit 2
elif [ -d "$file" ];then
        echo "$file is a  目录文件"
elif [ -f "$file"  ];then
        echo "$file is a 普通文件"
else
        echo "你输入的文件是其他文件类型"
fi

以上是关于shell脚本之判断文件类型的主要内容,如果未能解决你的问题,请参考以下文章