linux shell 循环写在一行 for while

缺乏、安全感 2021-09-02 07:57 692阅读 0赞

for循环实例

间隔5秒查询tomcat进程是否存在,如果存在跳出循环,最多循环20次,等待100秒

  1. for i in $(seq 1 20); do ps aux| grep tomcat | grep -v grep && break;sleep 5;done

while循环实例

间隔5秒查询tomcat进程是否存在,如果存在跳出循环,如果不存在将一直等待

  1. while true; do ps aux | grep tomcat | grep -v grep && break;sleep 5; done

注意 分号后的空格 可加 可不加

以下代码也是可以正常运行的

  1. while true;do ps aux | grep tomcat | grep -v grep && break;sleep 5;done

发表评论

表情:
评论列表 (有 0 条评论,692人围观)

还没有评论,来说两句吧...

相关阅读