SHELL脚本练习:判断文件类型;
设计思路:
[ -z "$a" ] 是否为空
[ -e "file" ] 是否存在
[ -f "file" ] 普通文件
[ -b "file" ] 块设备
[ -S "file" ] 套接字
[ -c "file" ] 字符设备
[ -L "file" ] 软链接
exit 0 代表正常运行程序并退出程序,
#!/bin/bash
[ -z "$1" ] && {
echo "please enter the file name!"
exit 1
}
[ -e "$1" ] || {
echo "This file does not exist!"
exit 1
}
[ -f "$1" ] && {
echo "The file is a normal file."
}
[ -b "$1" ] && {
echo "The file is a block device."
}
[ -S "$1" ] && {
echo "The file is a socket."
}
[ -c "$1" ] && {
echo "The file is a character device.0"
}
[ -L "$1" ] && {
echo "The file is a soft link"