As we know, in bash programming the way to pass arguments is $1
, ..., $N
. However, I found it not easy to pass an array as an argument to a functio
You could pass the "scalar" value first. That would simplify things:
f(){
b=$1
shift
a=("$@")
for i in "${a[@]}"
do
echo $i
done
....
}
a=("jfaldsj jflajds" "LAST")
b=NOEFLDJF
f "$b" "${a[@]}"
At this point, you might as well use the array-ish positional params directly
f(){
b=$1
shift
for i in "$@" # or simply "for i; do"
do
echo $i
done
....
}
f "$b" "${a[@]}"