37 lines
553 B
Bash
37 lines
553 B
Bash
|
#!/bin/bash
|
||
|
|
||
|
echo "Using test -e:"
|
||
|
test -e "$1"
|
||
|
echo $?
|
||
|
|
||
|
echo "Using [ -d ]:"
|
||
|
[ -d "$1" ]
|
||
|
echo $?
|
||
|
|
||
|
echo "Using [ -x ]:"
|
||
|
[ -x "$1" ]
|
||
|
echo $?
|
||
|
|
||
|
# 判断文件是否存在
|
||
|
# test -e "$1" # 与下面等价
|
||
|
# [ -e "$1" ] # 与上面等价
|
||
|
|
||
|
# 更多判断
|
||
|
# -d 是目录
|
||
|
# -f 是文件
|
||
|
# -e 是存在
|
||
|
# -r 是可读
|
||
|
# -w 是可写
|
||
|
# -x 是可执行
|
||
|
# -s 是非空
|
||
|
# -h 是软链接
|
||
|
# -L 是软链接
|
||
|
# -p 是管道
|
||
|
# -S 是socket
|
||
|
# -b 是块设备
|
||
|
# -c 是字符设备
|
||
|
# -t 是终端
|
||
|
# -g 是设置了组ID
|
||
|
# -u 是设置了用户ID
|
||
|
# -k 是设置了粘滞位
|