Reputation: 64925
I am calling a bash function like so:
func "foo-A-bar foo-B-bar foo-C-bar"
I would like to replace the above with a brace expansion that evaluates to the same single argument. The following doesn't work:
func foo-{A,B,C}-bar
because that's three separate arguments, not one argument with space-separated values. That is, it is equvalent to:
func foo-A-bar foo-B-bar foo-C-bar
which is not the same thing as the original call.
Upvotes: 1
Views: 302
Reputation: 85580
You can construct the brace expansion result into a positional argument list and expand the arguments as a single expanded string.
set -- foo-{A,B,C}-bar
func "$*"
The set
command with the result of the brace expansion, sets the arguments from $1
as foo-A-bar
and $2
as foo-B-bar
respectively. With these positional arguments in-place, the array expansion $*
causes them arguments to be combined as a single string joined by the default IFS
value ( a single white-space )
Upvotes: 2
Reputation: 785146
You may use command substitution:
func "$(echo foo-{A,B,C}-bar)"
which is equivalent of using:
func "foo-A-bar foo-B-bar foo-C-bar"
Upvotes: 0