Использовать 0 в качестве значений по умолчанию от $ 1 до $ 9:
SUM() {
echo "The sum is $((${1:-0}+${2:-0}+${3:-0}+${4:-0}+${5:-0}+${6:-0}+${7:-0}+${8:-0}+${9:-0}))"
}
From man bash:
${parameter:-word}
Use Default Values. If parameter is unset or null, the expansion
of word is substituted. Otherwise, the value of parameter is
substituted.
Примеры:
$ SUM
Сумма равна 0
$ SUM 1 2
Сумма равна 3
$ SUM 1 1 1 1 1 1 1 1 1
Сумма равна 9
Тот же вывод с awk:
SUM() {
echo -e ${@/%/\\n} | awk '{s+=$1} END {print "The sum is " s}'
}