Printing the sum of a numbers

Hi

I am writing a script that will produce the total of the digits with in the number. Here is the script.

[root@***/]-bash# cat Sum_Digits
if [ "$? -lt 1" ]
then
echo "You must enter at least two digits"
echo "If you enter more than two digits after the base line program this script will print the sum of the digits"
echo "For examples if you enter $0 456 then this script will print the sum of the three digits as 15 (4+5+6)"
fi

n=$1
sd=0
sum=0

while [ "$n" -gt "0" ]
do
sd=`expr $n % 10`
sum=`expr $sum + $sd`
n=`expr $n / 10`
done

echo "The sum of the number: $sum"

The script works fine when I mentioned the number following the base line program as shown below

[root@*** /]-bash# ./Sum_Digits 45667
You must enter at least two digits
If you enter more than two digits after the base line program this script will print the sum of the digits
For examples if you enter ./Sum_Digits 456 then this script will print the sum of the three digits as 15 (4+5+6)
The sum of the number: 28

But it fails when I just enter the script with out any number

[root@crjueyudev01 /]-bash# ./Sum_Digits
You must enter at least two digits
If you enter more than two digits after the base line program this script will print the sum of the digits
For examples if you enter ./Sum_Digits 456 then this script will print the sum of the three digits as 15 (4+5+6)
./Sum_Digits: line 12: [: : integer expression expected
The sum of the number: 0

I tried with out quotes and the error message comes back as usual

Thanks

if [ "${#}" -lt 1 ]

This is the part of the revised script
if [ "${#}" -lt 1 ]
then
sd=`expr $n % 10`
sum=`expr $sum + $sd`
n=`expr $n / 10`
fi

This is the output

You must enter at least two digits
If you enter more than two digits after the base line program this script will print the sum of the digits
For examples if you enter ./welcome 456 then this script will print the sum of the three digits as 15 (4+5+6)
expr: syntax error
expr: syntax error
expr: syntax error
The sum of the number:

Thanks

read num

case $num in
     "" | [0-9]) echo "Must be at least two digits" >&2; exit 1 ;;
     *[!0-9]*) echo Invalid number >&2; exit 2;;
esac

total=0
while [ -n "$num" ]
do
  temp=${num%?}
  total=$(( $total + ${num#"$temp"} ))
  num=$temp
done
echo $total

Hi vgersh99 and cfajohnson

Thank you for your attention and help. It is solved.

Regards