方式一:计数器控制while的循环
#!/bin/bash
sum=0i=0while (( i <= 100 ))do let "sum=sum+$i" let "i=i+2"doneecho $sum方式二:结束标记控制循环
read -p "please input a num[1-10] " num2
while [[ "$num" != 5 ]]do if [ "$num" -lt 5 ];then echo "too small,try again" read num elif [ "$num" -gt 5 ];then echo "too big ,try again" read num else exit 0 fidoneecho "you are right"方式三:标志控制的while循环
#!/bin/bash
read -p "please input a num [1-10]" numsignal=0while [[ "$signal" != 1 ]]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 signal=1 fidoneecho "you are right"方式四:命令行控制的while循环
#!/bin/bash
##第四种while使用方式echo "number of arguement: $#"echo "what you input is:"while [[ "$*" != "" ]]do echo "$1" shiftdone