In bash one can escape arguments that contain whitespace.
foo \"a string\"
This also works for arguments to a command or function:
There are (at least) two ways to do this:
Use an array and expand it using "${array[@]}":
bar() {
local i=0 args=()
for arg in "$@"
do
args[$i]="prefix $arg"
((++i))
done
foo "${args[@]}"
}
So, what have we learned? "${array[@]}" is to ${array[*]} what "$@" is to $*.
Or if you do not want to use arrays you need to use eval:
bar() {
local args=()
for arg in "$@"
do
args="$args \"prefix $arg\""
done
eval foo $args
}