Knowing I am able to run echo
or mv
to expand patterns like these: echo {0..9}{A..Z}
. I am curious to know if there is a way to do the sam
You can use eval
:
eval docker-compose\ {stop,rm,'up -d'}\;
Careful escaping/quoting is needed, though. Just test with echo
instead of docker
that it emits the correct commands:
$ echo docker-compose\ {stop,rm,'up -d'}\;
docker-compose stop; docker-compose rm; docker-compose up -d;
Not the way you mention it.
Brace expansion occurs before any other expansion. This means that when you say echo {0,1}{a,b}
, Bash expands the braces before going through any other step. This way, it becomes echo 0a 0b 1a 1b
, a single command.
When you mention docker-compose {stop,rm,up -d}
, note this would expand to a single command: docker-compose stop rm up -d
, which doesn't seem to be valid.
It looks like you would like to run three different commands:
docker-compose stop
docker-compose rm
docker-compose up -d
For this, you may want to use a loop (note "up -d" is quoted so that it is treated as a single argument):
for argument in stop rm "up -d"
do
docker-compose $argument
done