这段代码用于检查文件是否存在:
#!/bin/bash
FILE=$1
if [ -f $FILE ]; then
echo "File $FILE exists."
else
echo "File $FILE does not exist."
fi
如何仅检查文件不存在?
test 命令(这里写作 [)有一个 “not” 逻辑运算符,即感叹号 !:
if [ ! -f /tmp/foo.txt ]; then
echo "File not found!"
fi
文章介绍了在Bashshell中使用`-f`测试和`test`命令(带有`!`操作符)来判断文件是否存在,包括示例代码演示了如何检查指定文件及其不存在的情况。
1910

被折叠的 条评论
为什么被折叠?



