3

i have recently learned how can i use curly braces to run multiple commands using curly braces for example, i can create 10 files like this,

touch {1..10}.txt

or file with odd names,

touch {1..10..2}

I can also restart multiple process like,

systemctl restart app9-{server,client,test}

above command will restart services called, app9-server , app9-client and app9-test

now i have a command with a space in it,

vagrant destroy app9
vagrant up app9
vagrant ssh app9

how can i run above 3 commands using braces?

I tried,

vagrant {destroy app9,up app9,ssh app9}

and

vagrant {destroy,up,ssh} app9

but none of them actually works.

Can someone please tell me how can i run these commands using braces?

MaverickD
  • 359
  • 2
  • 11
  • 1
    Does `vagrant destroy app9 up app9 ssh app9` or `vagrant destroy up ssh app9` work? – muru Oct 01 '18 at 03:34
  • no it doesn't but `vagrant destroy app9 && vagrant up app9 && vagrant ssh app9` does. – MaverickD Oct 01 '18 at 03:39
  • when i run `vagrant {destroy app9,up app9,ssh app9}` it outputs as if i ran `vagrant` command only without any parameters – MaverickD Oct 01 '18 at 03:41
  • 1
    So you need to run those as separate commands, and brace expansion won't help much with that. See dupe^ – muru Oct 01 '18 at 03:43

2 Answers2

2

In none of the cases where you use curly braces in your question are you running multiple commands.

touch {1..10}.txt

runs one command on 10 files:

touch 1.txt 2.txt 3.txt 4.txt 5.txt 6.txt 7.txt 8.txt 9.txt 10.txt

The command

systemctl restart app9-{server,client,test}

is still just one command:

systemctl restart app9-server app9-client app9-test

Brace expansion is used to perform a simple text expansion of one or several strings in a single command.

The three tasks you want to perform must be three separate commands. You may do this in a loop if you wish:

for cmd in destroy up ssh; do
    vagrant "$cmd" app9
done
Kusalananda
  • 320,670
  • 36
  • 633
  • 936
1

Try:

eval 'vagrant '{destroy,up,ssh}' app9;'

Notice the quotes.