如何检查shell脚本中是否存在文件
发布时间:2020-12-15 19:04:13 所属栏目:安全 来源:网络整理
导读:我想编写一个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 arch
我想编写一个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 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |