首页 > 代码库 > 条件语句示例

条件语句示例

一、while语句

declare -i i=0
declare -i sum=0
while [ ${i} != 100 ]
do
        i=$((${i}+1))
#       echo "i=${i}"
        sum=$((${sum}+${i}))
done
echo "${sum}"



二、for语句

mypath=/etc/passwd

myusers=$(cat ${mypath} | awk -F":" ‘{print $1}‘)

for users in ${myusers}
do
        id ${users}
done
exit 0


三、for语句

for nethost in $(seq $2 $3)


四、for语句

sum=0
for (( i=1; i<=$1 ; i=i+1 ))
do
        sum=$((${sum}+${i}))
done
echo "the sum is:${sum}"
exit 0



本文出自 “7995400” 博客,请务必保留此出处http://8005400.blog.51cto.com/7995400/1913226

条件语句示例