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