脚本

[root@lynn-04 shell]# vim while2.sh

#!/bin/bash
i=6
while [ $i -gt 0 ]
do
    i=$[$i-1]
    echo $i
done

执行结果

[root@lynn-04 shell]# sh while2.sh
5
4
3
2
1
0

脚本

[root@lynn-04 shell]# vim while1.sh

#!/bin/bash
load=`w|head -1|awk -F 'load average: ' '{print $2}'|cut -d. -f1`
while [ $load -lt 10 ]
do
    echo $load
    /usr/lib/zabbix/alertscripts/mail.py 15******[email protected] "load high" "$load"
    exit
done

执行结果 这里是发邮件的脚本 当然我的邮箱也会收到报警邮件

[root@lynn-04 shell]# sh while1.sh
0

9*9乘法口诀
脚本

[root@lynn-04 shell]# vim 99.sh

#!/bin/bash
echo "9*9======"
i=1
j=1
line=""
while [[ i -lt 10 ]];
do
j=1
line=""
until [[ j -eq 10 ]];    #until和while相反,表示条件不满足执行循环
do
      if [[ j -le i ]];
      then
          result=$(expr $i \* $j)
          resultStr="$j X $i = $result"
          line=${line}${resultStr}"\t"
      fi
j=$(expr $j + 1)
done
    echo -e ${line}
    i=$(expr $i + 1)
done
echo "9*9======"

执行结果

[root@lynn-04 shell]# sh 99.sh
9*9======
1 X 1 = 1   
1 X 2 = 2   2 X 2 = 4   
1 X 3 = 3   2 X 3 = 6   3 X 3 = 9   
1 X 4 = 4   2 X 4 = 8   3 X 4 = 12  4 X 4 = 16  
1 X 5 = 5   2 X 5 = 10  3 X 5 = 15  4 X 5 = 20  5 X 5 = 25  
1 X 6 = 6   2 X 6 = 12  3 X 6 = 18  4 X 6 = 24  5 X 6 = 30  6 X 6 = 36  
1 X 7 = 7   2 X 7 = 14  3 X 7 = 21  4 X 7 = 28  5 X 7 = 35  6 X 7 = 42  7 X 7 = 49  
1 X 8 = 8   2 X 8 = 16  3 X 8 = 24  4 X 8 = 32  5 X 8 = 40  6 X 8 = 48  7 X 8 = 56  8 X 8 = 64  
1 X 9 = 9   2 X 9 = 18  3 X 9 = 27  4 X 9 = 36  5 X 9 = 45  6 X 9 = 54  7 X 9 = 63  8 X 9 = 72  9 X 9 = 81  
9*9======