linux shell 循环写在一行 for while
for循环实例
间隔5秒查询tomcat进程是否存在,如果存在跳出循环,最多循环20次,等待100秒
for i in $(seq 1 20); do ps aux| grep tomcat | grep -v grep && break;sleep 5;done
while循环实例
间隔5秒查询tomcat进程是否存在,如果存在跳出循环,如果不存在将一直等待
while true; do ps aux | grep tomcat | grep -v grep && break;sleep 5; done
注意 分号后的空格 可加 可不加
以下代码也是可以正常运行的
while true;do ps aux | grep tomcat | grep -v grep && break;sleep 5;done
还没有评论,来说两句吧...