认识while循环bash
用法1、死循环,:在while循环里面表示永久为真ide
[root@localhost test]# cat 7.shinput
#!/bin/bashit
while :class
dotest
date +%Tsed
sleep 5date
done循环
用法2、顺序输出1-10di
[root@localhost test]# cat 8.sh
#!/bin/bash
n=1
while [ $n -le 10 ]
do
echo $n
n=$[$n+1]
done
用法3、检测用户输入
[root@localhost test]# cat 9.sh
#!/bin/bash
while :
do
read -p "Please input a number: " m
n=`echo $m | sed 's/[0-9]//g'`
if [ -z "$n" ]
then
echo $m
exit
fi
done
用法4、检测用户输入
[root@localhost test]# cat 9.sh
#!/bin/bash
n=1
while [ ! -z "$n" ]
do
read -p "Please input a number: " m
n=`echo $m | sed 's/[0-9]//g'`
echo $m
done