语法: while 条件; do 内容… ; done
#!/bin/bash
#执行sh -x while1.sh:每隔30秒检查系统负载,当负载达到10,发一份邮件 !
while true #可以写成 while :
do
load=`w|head -1|awk -F 'load average: ' '{print $2}'|cut -d. -f1`
if [ $load -gt 10 ]
then
/usr/local/sbin/mail.py zhu0000@163.com "load load" "$load"
fi
sleep 30
done
#!/bin/bash
#执行sh -x while2.sh:让用户不断的输入纯数字,才停止换算 !
while :
do
read -p "Please input a number: " n
if [ -z "$n" ] --表示当变量的值为空时会怎么样
then
echo "you need input sth."
continue
fi
n1=`echo $n|sed 's/[-0-9]//g'`
if [ -n "$n1" ] --表示当变量的值不为空
then
echo "you just only input numbers."
continue
fi
break
done
echo $n