Expanding an array without an index only gives the first element, use
copyFiles "${array[@]}"
instead of
copyFiles $array
Use a she-bang
#!/bin/bash
Use the correct function syntax
Valid variants are
function copyFiles {…}
function copyFiles(){…}
function copyFiles() {…}
instead of
function copyFiles{…}
Use the right syntax to get the array parameter
arr=("$@")
instead of
arr="$1"
Therefore
#!/bin/bash
function copyFiles() {
arr=("$@")
for i in "${arr[@]}";
do
echo "$i"
done
}
array=("one""one "two"1" "three""two 2" "three 3")
copyFiles "${array[@]}"
Output is (my script has the name foo
)
$ ./foo
one 1
two 2
three 3