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
}
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<
func2 "${files1[@]}" "${files2[@]}"and havefunc2know where the arguments fromfiles1end and the arguments fromfiles2begin.