认识while循环

用法一、死循环,:在while循环里面表示永久为真

[root@localhost test]# cat 7.sh

#!/bin/bash

while :

do

date +%T

sleep 5

done

用法二、顺序输出1-10

[root@localhost test]# cat 8.sh

#!/bin/bash

n=1

while [ $n -le 10 ]

do

echo $n

n=$[$n+1]

done

用法三、检测用户输入

[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

用法四、检测用户输入

[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