首先, bash中命令执行成功返回状态码 0, 失败返回非0状态码(以下$是终端提示符)
$ true; echo $?
0
$ false; echo $?
1
1. while
$ while true; do echo good; break; done
good
$ while [ 1 -eq 1 ]; do echo good; break; done
good
$ while ps -ef | grep grep; do echo good; break; done
good
2. util
$ until false; do echo good; break; done
good
$ until [ 1 -ne 1 ]; do echo good; break; done
good
$ until ps -ef | grep grep | grep -v grep; do echo good; break; done
good
由此可见,while表示如果条件为真则进入循环,until表示条件为真则不进入循环。
原文地址:https://www.cnblogs.com/lyg-blog/p/11746329.html
时间: 2024-10-06 23:28:34