标签:linux脚本
1、
#!/bin/bash
#0~100相加,for循环
declare -i i
declare -i sum
for i in {1..100};do
let sum+=i
let i++
done
echo $sum
2、
#!/bin/bash
#0~100相加,until循环
declare -i x=0
declare -i sum
until [ $x -gt 100 ]
do
let sum+=x
let x++
done
echo -e "the result is $sum"
3、
#!/bin/bash
#0~100相加,用while循环
declare -i x=0
declare -i sum
while((x<=100))
do
let sum+=x
let x++
done
echo $sum
本文出自 “11944248” 博客,请务必保留此出处http://11954248.blog.51cto.com/11944248/1963796
标签:linux脚本
原文地址:http://11954248.blog.51cto.com/11944248/1963796