Check if file exists and continue else exit in Bash

给你一囗甜甜゛ 提交于 2019-12-04 22:44:04

Change it to this:

{
if [ ! -f /scripts/alert ]; then
    echo "File not found!"
    exit 0
fi
}

A conditional isn't a loop, and there's no place you need to jump to. Execution simply continues after the conditional anyway.

(I also removed the needless &&. Not that it should happen, but just in case the echo fails there's no reason not to exit.)

Pluckerpluck

Your problem is with the continue line which is normally used to skip to the next iteration of a for or while loop.

Therefore just removing the else part of your script should allow it to work.

Yes. Drop the else continue. It's entirely unneeded.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!