exit 完全中断脚本的执行
break 中断脚本的循环,但是会执行循环外的语句
continue 跳出本次循环,进行下一次循环
实验测试:
[root@localhost mnt]# vim file.sh
[root@localhost mnt]# sh file.sh [root@localhost mnt]# sh file.sh exit [root@localhost mnt]# sh file.sh break [root@localhost mnt]# sh file.sh continue
for NUM in 1 2 3 #指定循环内容1 2 3 for NUM in {1..3} #指定循环内容{1..3} for NUM in `seq 1 3` for NUM in `seq 1 2 10` ##1-10个数里步距为2
实验测试:
[root@localhost mnt]# vim for.sh [root@localhost mnt]# sh for.sh
[root@localhost mnt]# vim for.sh [root@localhost mnt]# sh for.sh
[root@localhost mnt]# vim check_host.sh [root@localhost mnt]# sh check_host.sh
[root@localhost mnt]# yum install mariadb-server.x86_64 -y ##安装数据库 [root@localhost mnt]# systemctl start mariadb ##开启服务 [root@localhost mnt]# vim mysql_dump.sh
[root@localhost mnt]# sh mysql_dump.sh [root@localhost mnt]# ls [root@localhost mnt]# ls mysql_backup/ [root@localhost mnt]# vim mysql_dump.sh
while true 条件为真就执行 do done
[root@localhost mnt]# vim test.sh [root@localhost mnt]# sh test.sh
[root@localhost mnt]# df ##查看负载量 [root@localhost mnt]# vim checkload.sh
[root@localhost mnt]# dd if=/dev/zero of=/bigfile bs=1M count=6000 ##截取6000M保证负载超过80%来进行实验查看 [root@localhost mnt]# df ##查看负载已经超过80%
[root@localhost mnt]# sh checkload.sh & ##在后台运行脚本 [1] 3250 [root@localhost mnt]# mail ##查看邮件
[root@localhost mnt]# vim checkload.sh
[root@localhost mnt]# sh checkload.sh [root@localhost mnt]# sh checkload.sh & [2] 4973 [root@localhost mnt]# Your / will full !! ##自动弹出负载已满80%