There are couple of problems. Here is the working form :
#!/bin/bash
function copyFiles {
arr=( "$@" )
for i in "${arr[@]}";
do
echo "$i"
done
}
array=("one" "two" "three")
copyFiles "${array[@]}"
There need to be at least a space between function declaration and
{
You can not use
$array
, asarray
is an array not a variable. If you want to get all the values of an array use"${array[@]}"
In you main function declaration you need
arr="$@"
as"${array[@]}"
will expand to the indexed values separated by spaces, if you use$1
you would get only the first value. To get all the values usearr="$arr[@]arr="${arr[@]}"
.