Struggling for a while passing an array as argument but it's not working anyway. I've tried like below:
#! /bin/bash
function copyFiles{
arr="$1"
for i in "${arr[@]}";
do
echo "$i"
done
}
array=("one" "two" "three")
copyFiles $array
An answer with explanation would be nice.
Edit: Basically, i will eventually call the function from another script file. Plz explain the constraints if possible.
Best Answer
Expanding an array without an index only gives the first element, use
instead of
Use a she-bang
Use the correct function syntax
Valid variants are
instead of
Use the right syntax to get the array parameter
instead of
Therefore
Output is (my script has the name
foo
)