The following safely handles array elements containing spaces. Other solutions I've found do not.
#! /bin/bash # $ ./return_an_array.sh # ./return_an_array.sh: line 9: declare: returned_array: not found # declare -a returned_array='([0]="one" [1]="two three")' return_an_array() { local -a an_array=( 'one' 'two three' ) declare -p an_array } declare -p returned_array eval $(return_an_array | sed -e 's/^\(declare -a \)[^=]*=/\1 returned_array=/') declare -p returned_array