Files
notes_estom/Linux/shell/test05.sh
法然 dd11a44b1f shell
2022-10-03 00:08:52 +08:00

34 lines
974 B
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
#判断用户输入的是什么文件
read -p "Please input a filename: " file
#接收键盘的输入并赋予变量file
if [ -z "$file" ]
then
#判断file变量是否为空
echo "Error, please input a filename"
# 如果为空执行程序1也就是输出报错信息
exit 1
# 退出程序,并返回值为Ⅰ(把返回值赋予变量$P
elif [ ! -e "$file" ]
then
#判断file的值是否存在
echo "Your input is not a file!"
#如1果不存在则执行程序2
exit 2
#退出程序把并定义返回值为2
elif [ -f "$file" ]
then
#判断file的值是否为普通文件
echo "$file is a regulare file!"
#如果是普通文件则执行程序3
elif [ -d "$file" ]
then
#到断file的值是否为目录文件
echo "$file is a directory!"
#如果是目录文件网执行程序4
else
echo "$file is an other file!"
#如果以上判断都不是则执行程序5
fi
```