首先, bash中命令執行成功返回狀態碼 0, 失敗返回非0狀態碼(如下$是終端提示符)
$ true; echo $?
bash
0
$ false; echo $?
1
$ while true; do echo good; break; done
code
good
$ while [ 1 -eq 1 ]; do echo good; break; done
good
$ while ps -ef | grep grep; do echo good; break; done
good
$ 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表示條件爲真則不進入循環。終端