#!/usr/bin/env bash set -e set -u myfunc() { local myresult='some value' echo $myresult } result="$(myfunc)" get_files() { cd Applications local -n arr=$1 local FILES=(one two) for file in "$PWD"/*; do if [[ $file == ./install.sh ]]; then echo "das" elif [[ $file == *.sh ]]; then arr+=(${file##*/}) fi done echo ${FILES[@]} } # https://stackoverflow.com/questions/10582763/how-to-return-an-array-in-bash-without-using-globals # get_files() array=() get_files array # VAR+=("$(get_files)") # echo "${VAR[-1]}" for i in "${arr[@]}"; do echo $i done