#!/bin/bash
#测试1+2+3+...10=?
total (){
num=0
sum=0
while [ ${num} -lt 10 ]
do
num=`expr ${num} + 1`
sum=`expr ${sum} + ${num}`
done
return ${sum}
}
total
echo "1+2+3+....10=$?
运行结果为:1+2+3+....10=55
#!/bin/bash
#测试1+2+3+...10=?
total (){
num=0
sum=0
while [ ${num} -lt 10 ]
do
num=`expr ${num} + 1`
sum=`expr ${sum} + ${num}`
done
return ${sum}
}
total
echo "1+2+3+....10=$?
运行结果为:1+2+3+....10=55