如果无法找到或读取文件,如何杀死Bash脚本?

VAR*_*121 0 bash

我写了一个小的bash程序,需要读取一个带有名字的文件input.我希望脚本打印消息file not found,如果找不到文件则退出或自行终止.

P.P*_*.P. 5

在阅读之前,检查文件是否存在:

if [ ! -f input ]; then
  echo "File Not found"
  exit 1
fi
Run Code Online (Sandbox Code Playgroud)