I'm attempting to write a function that writes arrays with a name that's passed in. Given the following bash function:
function writeToArray {
    local name="$1"
    echo "$name"
    declare -a "$name"
    ${name[0]}="does this work?"      
}
Running like this:
writeToArray $("test")
I get two errors:
bash: declare: `': not a valid identifier
=does this work?: command not found
I am expecting to be able to do this:
writeToArray $("test")
for item in "${test[@]}"; do
        echo "item"
        echo "$item"
done
This should print:
item
does this work?
How could I properly configure this to write the array (named test in the example, such that this array named test is readable outside the function)?

