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"