How do I pass an array to a function, and why wouldn’t this work?
The solutions in other questions didn’t work for me.
For the record, I don’t need to copy the array so I don’t mind passing a reference. All I want to do is loop over it.
$ ar=(a b c)
$ function test() { echo ${1[@]}; }
$ echo ${ar[@]}
a b c
$ test $ar
bash: ${1[@]}: bad substitution
$ test ${ar[@]}
bash: ${1[@]}: bad substitution
1 Answer