#!/bin/bash
#sum 1-*
#by wangyq 2017
a=0
while [ $a -lt 1 ]
do
read -p "please input number:" a
done
sum=0
for i in `seq 1 $a`
do
sum=$[$i+$sum]
done
#sum 1-*
#by wangyq 2017
a=0
while [ $a -lt 1 ]
do
read -p "please input number:" a
done
sum=0
for i in `seq 1 $a`
do
sum=$[$i+$sum]
done
echo $sum
--------------------------------------------------------------------------
#!/bin/bash
#sum 1-*
#by wangyq 2017
a='abc'
if_a() {
m=`echo $1|sed 's/[0-9]//g'`
if [ ! -z $m ] || [ $a -eq 0 ]
then
return 1
else
return 0
fi
}
while ! if_a $a
do
read -p "please input number:" a
done
sum=0
for i in `seq 1 $a`
do
sum=$[$i+$sum]
done
echo $sum