Reputation: 157
I have two functions and im trying to figure out how to pass a list to a function call from within another function
func1{
files=()
$(func2 ${files[@]})
}
func2{
#do something with the list
}
Upvotes: 0
Views: 408
Reputation: 117258
Make sure you have quotes ("
) around your list when you do the call to preserve any spaces that might be in the individual strings in the list.
Example:
#!/bin/bash
function func1 {
files=("foo bar" "hello world")
func2 "${files[@]}"
}
function func2 {
for var in "$@"; do
echo ">$var<"
done
}
func1
Output:
>foo bar<
>hello world<
Upvotes: 2