I want to create a bash function bar that takes a function foo as an argument but have foo also take parameters.
function foo() {
foo_args=("$@")
for i in "${foo_args[@]}";
do
echo "$i"
done
}
function bar() {
($1)
}
foo_args=(
"one" "two" "three"
)
bar foo foo_args
How do I pass foo_args to bar?
EDIT:
I tried:
bar foo "${foo_args[@]}"
With:
function bar() {
params="${3}"
($1 ${params[@]})
}
But foo only looks at the first element.
bar()function has no meaning at all. Also yourfoo()function never gets invokedaction_needed, andfoois any action that actually performs something.foo's arguments are whatfooacts on. There might be many actions needed, but they all have the same warning message.