文件判断参数
- -e,文件是否存在
- -f,文件存在且为普通文件
- -d,文件存在且为文件夹
1 #!/bin/bash 2 3 [ -e test.sh ] && echo "test.sh exits" 4 [ -f test.sh ] && echo "test.sh exits and it's a regular file" 5 [ -d test.sh ] && echo "test.sh is a directory"
- 注意做判断语句的中括号需要空格。
1 #!/bin/bash 2 3 [ -e test.sh ] && echo "test.sh exits" 4 [ -f test.sh ] && echo "test.sh exits and it's a regular file" 5 [ -d test.sh ] && echo "test.sh is a directory"