如何检查shell脚本中是否存在文件

前端之家收集整理的这篇文章主要介绍了如何检查shell脚本中是否存在文件前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想编写一个shell脚本来检查某个文件archived_sensor_data.json是否存在,如果存在,则删除它.在 http://www.cyberciti.biz/tips/find-out-if-file-exists-with-conditional-expressions.html之后,我尝试了以下方法
[-e archived_sensor_data.json] && rm archived_sensor_data.json

但是,这会引发错误

[-e: command not found

当我尝试使用./test_controller命令运行生成的test_controller脚本时.代码有什么问题?

括号和-e之间缺少空白.
#!/bin/bash
if [ -e x.txt ]
then
    echo "ok"
else
    echo "nok"
fi
原文链接:https://www.f2er.com/bash/387220.html

猜你在找的Bash相关文章