Adding numbers, break on non-numbers...
Hi agian...
2 biiiiiig problems on the same day.... maybe I should have stayed in bed this morning...
Anyways... trying to help a friend with a problem...
He's trying to write a script that adds numbers that are written in when executing the script...
What I've come up with this far is:
-----------------------------------------------------------------------------
#!/bin/bash
sum=0
for i in $*
do
sum=`expr $i + $sum`
done
echo "The sum of the numbers entered is $sum"
------------------------------------------------------------------------------
The only problem is that he want's it to break if a letter (character, non-numberic) is entered... how do I solve this?
|