while循環格式
while expression
do
command
......
done
第一種:計數器控制的循環
counter=1
let command to operate counter
例:
#!/bin/bash
a=1
while (( "$a"<=4 ))
echo "$a"
let "a++"
第二種:結束标記控制的循環
read variable
while [[ "$variable != sentinel ]]
do
read variable
#!/bin/bash
echo "input the num(1-10)"
read num
while [[ "$num !=4 ]]
if [ "$num" -lt 4 ]
then
echo "Too smanll.Try again"
read num
elif [ "$num" -gt 4 ]
echo "to hgh.Tyr again"
else
exit 0
fi
echo "you are right"
第三種:标志控制的循環
signal=0
while (( signal != 1 ))
...
if expression
signal=1
echo "Please input the num"
while [[ "$signal" != 1 ]]
if [ "$num" -lt 4 ]
echo "Too small,Tye again"
read num
else [ "$num" -gt 4 ]
echo "To high.Try again"
read num
signal=1
echo "you are right"
fi
第四種:指令行控制的循環
while [[ "$*" != " " ]]
echo "$1"
shift
echo "number of arguments is $#"
echo "what you input is:"