while循环的格式css
while expressionexpress
doide
commandspa
command命令行
```ci
doneinput
一、计数器控制的while循环it
#!/bin/shio
int=1class
while(( $int<=5 ))
do
echo $int
let "int++"
done
二、结束标记控制的while循环
#用脚本演示使用结束标记控制while循环实现猜1~10内的数
#!/bin/sh
echo "Please input the num (1~~10): "
read num
while [[ $num != 4 ]]
do
if [ $num -lt 4 ]
then
echo "Too small ,Try again.."
read num
elif [ $num -gt 4 ]
then
echo "Too big ,Try again.. "
read num
else
exit 0
fi
done
echo "Yes ,you are right !!"
三、标致控制的while循环
#!/bin/sh
echo "Please input the num:"
read num
sum=0
i=1
signal=0
while [[ $signal != 1 ]]
do
if [ $i -eq $num ]
then
let "signal=1"
let "sum+=i"
echo "1+二、、、+$num=$sum"
else
let "sum=sum+i"
let "i++"
fi
done
四、命令行参数控制的while循环
#!/bin/sh
echo "Please input arguements is $# "
echo "What you input : "
while [[ $* != "" ]]
do
echo $1
shift
done