This question is inspired by bash nested variable in for loop.
If I have an array in bash, and I want to be able to run an arbitrary command for every element of that array, is there a way to do that via a generic function, as opposed to with a loop? That is:
dest_array=( host1:/foo host2:/bar host3:/baz )
copy ./file dest_array
and have each expansion called:
copy ./file host1:/foo
copy ./file host2:/bar
copy ./file host3:/baz
Even better, is there a way to do this for multiple arrays? For instance:
sources=( first second )
dests=( host1:/foo host2:/bar )
copy sources dests
invoking (in no particular order):
copy first host1:/foo
copy first host2:/bar
copy second host1:/foo
copy second host2:/bar