When I needed to run a command multiple times with a different argument I used this approach (without understanding it fully):
touch {a,b,c}
Which is equivalent of:
touch a
touch b
touch c
I think the same could be accomplished with the following loop:
for file in {a,b,c}; do touch $file; done
However I've stumbled across a case where this does not work:
pear channel-discover {"pear.phpunit.de","pear.symfony-project.com"}
I have a few questions:
That's called Brace Expansion, which expands to a space-separated list of the given strings.
So touch {a,b,c}
would be equivalent to
touch a b c
While touch {a,b,c}x
would be equivalent to:
touch ax bx cx
You pear
command would essentially be run as:
pear channel-discover pear.phpunit.de pear.symfony-project.com
which may not be what you expected. If you want the command to be run once for each string, use a for loop (which answers your 2nd question), or use a combination of brace expansion and xargs.
The problem is that contrary to your expectation, the brace expansion of
touch {a,b,c}
is equivalent to
touch a b c # NOT 3 separate invocations.
(Use echo {a,b,c}
to verify). It appears that pear channel-discover
does not accept two args. You will probably see the same error with
pear channel-discover pear.phpunit.de pear.symfony-project.com
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With