#!/bin/bash while : sum=0 do read -p "please enter a num,num must greater than 1>>" num if test $[num] -gt 1 then for i in `seq 1 ${num}` do sum=$[${i}+${sum}] #echo ${i} done printf "1 to %s sum is: %s \n" ${num} ${sum} break else echo your enter has error!! fi done