我想编写一个 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
关于shell - 如何在shell脚本中检查文件是否存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40082346/