plus1.sh
#!/bin/bash
n=0
for i in {0..100}
do
let "n = $n + $i"
done
echo $n
plus2.sh
#!/bin/bash
n=0
for i in `seq 100`
do
let "n = $n + $i"
done
echo $n
plus3.sh
#!/bin/bash
i=0
n=0
while(( $i<100 ))
do
i=$(($i+1))
n=$(($i+$n))
done
echo $n
[root@test ~]# time bash plus1.sh
5050
real 0m0.004s
user 0m0.001s
sys 0m0.001s
[root@test ~]# time bash plus2.sh
5050
real 0m0.005s
user 0m0.002s
sys 0m0.002s
[root@test ~]# time bash plus3.sh
5050
real 0m0.003s
user 0m0.000s
sys 0m0.001s
阅读(1016) | 评论(0) | 转发(0) |