I want to pass an array parameter to a function in bash, and writing some testing code as:
#!/bin/sh
function foo {
a=$1;
for i in ${a[@]} ; do
echo $i
done
}
names=(jim jerry jeff)
foo ${names[@]}
the above code just show jim, rather than the three j*. so my question is:
- why my code doesn't work
- what's the right way to do it