I am trying to sum up numbered columns and in order to tidy up the program I have wrote a function to do the adding of some numbers. I have a problem though with passing a variable to the function in the UNIX bash shell. The function only gives the first number in the variable list and does not add the rest. Can a variable not be passed to the function or am I missing something quite obvious here. The function that I wrote and the function call is shown below;
function add_num () {
sum=0
for NUM in $1
do
sum=`expr $sum + $NUM`
done
}
I call this function by function_name Variable_name as so:
add_num $column1
add_num $column2