shell语法while

来源:互联网 发布:淘宝企业店铺品牌授权 编辑:程序博客网 时间:2024/06/07 00:51
#!/bin/sh


# calculate the sum from 1 to n


# validate the varibles number
if [ $# -ne 2 ] ; then
echo "usage : sum.sh start end"
exit
fi


start=$1
end=$2
while [ $start -lt $end ]
do
sum=$sum+$start
echo "$sum"
start=$start+1
done


echo "the result is $sum"