检查文件是否存在:
#!/bin/bash
FILE=$1
if [ -f $FILE ]; then
echo "File $FILE exists."
else
echo "File $FILE does not exist."
fi
如何只检查文件是否不存在?
最佳答案
test
命令(此处写为 [
)有一个“非”逻辑运算符,!
(感叹号):
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
关于bash - 我如何判断一个文件在 Bash 中是否不存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/638975/