while 条件
do
done
实验:当脚本后第一串字符为happy时输出this is happy day;事实上,输入happy时while条件永远都会满足,就是说这时无限循环的
#!/bin/bash
while [ "$1" = "happy" ]
do
echo this\'s $1 day
done
执行结果
this is happy day
......
......
......
(无限循环)
break跳出当前循环
#!/bin/bash
for i in {1..10}
do
if [ "$i" == "7" ]
then
echo this\'s break test
break
fi
echo $i
done
echo end
脚本执行结果,最后echo end会被执行,break只是终止do内的当前动作
[root@server210 mnt]# sh for4.sh
1
2
3
4
5
6
this's break test
end
exit往往意味着整个脚本的结束
09 #!/bin/bash
10 for i in {1..10}
11 do
12 if [ "$i" == "7" ]
13 then
14 echo this\'s break test
15 exit
16 fi
17 echo $i
18 done
19 echo end
执行结果,最后echo end不会被执行
[root@server210 mnt]# sh for4.sh
1
2
3
4
5
6
this's break test
continue 结束当前命令继续执行其他动作
09 #!/bin/bash
10 for i in {1..10}
11 do
12 if [ "$i" == "7" ]
13 then
14 echo this\'s break test
15 continue
16 fi
17 echo $i
18 done
19 echo end
脚本执行结果
[root@server210 mnt]# sh for4.sh
1
2
3
4
5
6
this's break test
8
9
10
end