bash - 我如何判断一个文件在 Bash 中是否不存在?

标签 bash file-io scripting

检查文件是否存在:

#!/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/

相关文章:

vba - Excel 2007 VBA 宏逐行读取文本文件如何停止逗号 (,) 分隔

windows - Linux 上的键盘和鼠标交互

shell - 如何使用 echo 命令写入和附加到文件

ruby - Git post-receive hook不使用rbenv指定的ruby版本

bash - 如何将一个命名管道的输出反馈到另一个命名管道?

mysql - 一个简单的脚本,用于将所有 mysql 数据库备份到单独的文件夹中

c++ - fread 时在 C 中转换 float -> double 的问题

python - 在 python 中写入文件后,文件处理程序不打印

bash - 如何在 shell 脚本中声明和使用 boolean 变量?

bash - bash中的“set -e”是做什么的?