Выходные параметры

Функции

#local -n makes a reference (bash 4.3 and newer): the function
#gets the name of a variable and writes into that variable
getSum() {
    local -n result=$1
    result=$(($2 + $3))
}

sum=0
getSum sum 5 3
#sum is 8
#the name outside must differ from the name inside:
#getSum result 5 3 gives the warning "circular name reference"

#the second way, without a reference:
#printf -v writes the text into the variable with the given name
getProduct() {
    printf -v "$1" '%d' $(($2 * $3))
}

getProduct product 5 3
#product is 15

echo "sum is $sum"
echo "product is $product"