1、用shell写一个从1加到100的程序:
方法一:
#!/bin/bash
sum=0
for i in {1..100}
do
let sum+=$i
done
echo $sum
方法二:
#!/bin/bash
sum=0
for i in {1..100..1}
do
let sum+=$i
done
echo $sum
方法三:
#!/bin/bash
sum=0
for ((i=1;i<=100;i++))
do
let sum+=$i
done
echo $sum
方法四:
for((i=0;i<=100;i++));do ((sum=sum+i));done;echo $sum
方法五:
for((q=0;q<=100;q++));do w=`expr $w + $q`;done;echo $w
2、从1到100循环
方法一:
for i in {1..100};do echo $i;done
方法二:
for i in `seq 100`;do echo $i;done