while 死循环
vim while.sh
#!/bin/bash ## while : do date +%T sleep 3 done
: 永久帧
查看时间
3秒循环1次
打印1-10
#!/bin/bash ## n=1 while [ $n -le 10 ] do echo $n n=$[$n+1] done
交互循环
#!/bin/bash ## n=0 while [ ! -z "$n" ] do read -p "Please input a number:" m n=`echo $m |sed 's/[0-9]//g'` echo $m done
先给n赋值
$n为空循环结束
输入数值赋值$m
$n=$m的数字被空格替换,
输出$m
#!/bin/bash ## while : do read -p "Please input anumber:" m n=`echo $m |sed 's/[0-9]//g'` if [ -z "$n" ] then echo $m exit else echo "Not is a number." fi done