Несколько возвращаемых значений

Функции

#a function prints the values in one line,
#read splits the line into variables
getFirstLast() {
    local first=-1
    local last=-1
    if (($# > 0)); then
        first=$1
        #${@: -1} is the last argument
        last=${@: -1}
    fi
    echo "$first $last"
}

lst=(2 3 5)
read -r first last <<< "$(getFirstLast "${lst[@]}")"
#first is 2
#last is 5

#a trap: read at the end of a pipeline runs in a subshell,
#and its variables vanish with it
fromPipe=0
getFirstLast "${lst[@]}" | read -r fromPipe rest
#fromPipe is 0

echo "first is $first"
echo "last is $last"
echo "fromPipe is $fromPipe"