20 lines
437 B
Bash
20 lines
437 B
Bash
# Original sum function, only allows for two values
|
|
orig_sum() {
|
|
local value1=$1
|
|
local value2=$2
|
|
local result=$(( value1 + value2 ))
|
|
echo "The sum of ${value1} and ${value2} is ${result}"
|
|
}
|
|
|
|
# Improved sum function that allows as many as required
|
|
sum() {
|
|
local total=0
|
|
for value in $@; do
|
|
total=$(( total + value ))
|
|
done
|
|
|
|
# Write the result
|
|
echo "Summed $# values for a total of: ${total}"
|
|
}
|
|
|