一 while循环
1.语法
# 一、while语句结构:条件为真时,执行循环体代码
while 条件
do
循环体
done
# 二、until语法结构:条件为假时,一直执行循环体代码,直到条件变为真
until 条件
do
循环体
done
二 for循环
#===========》Shell风格语法
for 变量名 [ in 取值列表 ]
do
循环体
done
#===========》C语言风格语法
for ((初值;条件;步长))
do
循环体
done
# shell风格的for,常用in列表方式
for i in 1 2 3
for i in {1,2,3}
for i in {1..9}
for i in {9..1}
for i in {a..z}
for i in {A..Z}
for i in {X..Z}
for i in $(命令)
# 例如:for i in $(head -10 /etc/passwd);do echo $i|cut -d: - f1,2;done
for i in $(find ...)
三 continue与break
1.解释
continue:默认退出本次循环
break:默认退出本层循环