I often use brace expansion on the command line, because it's handy.
Example
{foo,bar}
expands to:
foo bar
Multiple brace expansion also expand, e.g.:
{foo,bar}Q{foo,bar}
would expand to:
fooQfoo fooQbar barQfoo barQbar
This is expected behavior, where the brace expansions are used in order.
My Question
Now, I'd like the output of any brace expansion (or other short command line trick) to be:
fooQfoo barQbar
Note: I'm using bash 3.2
Best Answer
I couldn't figure out how to get this done using only curly braces. I don't see a way to achieve this either, so unless someone more clever than I can figure out a way I'd say it's not possible.
As an alternative
Sample Data
Examples
This can be put into a command like this:
or this:
or this:
Why curly braces can't do this
If you look at your original example:
The way this gets expanded is as follows:
The mechanism that expanded this is called a Cartesian Product.
For example:
Or this:
There is no way to create a Cartesian Product that will result in:
You're only option is to either resort to trickery such as this:
And then put this into a Bash array:
The other option would be some "other method" such as the one I previously discussed above (using
xargs
) for example.References