Run a command multiple times with different subcommands

echo apt-get\ {update,-y\ upgrade}\ \&\& true | sudo bash
it's nice to be able to use the command `ls program.{h,c,cpp}`. This expands to `ls program.h program.c program.cpp`. Note: This is a text expansion, not a shell wildcard type expansion that looks at matching file names to calculate the expansion. More details at I often run multiple commands (like apt-get) one after the other with different subcommands. Just for fun this wraps the whole thing into a single line that uses brace expansion.

2015-09-22 00:48:26

What Others Think

Brace-expansion's great. I use it all the time. Unfortunately your command's not a great example. It's a nightmare of escaped spaces and ampersands. . To be great it would have to be: * shorter than the expanded command * easy to remember * easy to type . Your command is equivalent to: echo 'apt-get update && apt-get -y upgrade && true' | sudo bash . Which can be shortened to: echo 'apt-get update && apt-get -y upgrade' | sudo bash Which can be made shorter still by using 'here string' redirection: sudo bash <<< 'apt-get update && apt-get -y upgrade' . Both forms are much clearer than the original. . The best command (IMHO) is the one you can type quickly and reliably.
flatcap · 313 weeks ago
You are quite correct. However I did the use the word 'fun' rather than 'useful'. :-) I actually posted this in case it had other uses. I didn't realise you do string here documents. That's cool!
alecthegeek · 313 weeks ago
I prefer flatcap's way. You should not uselessly echo with pipe when you can use
Tatsh · 312 weeks and 6 days ago
great that i found this forum. People here are great. Learned alot. Keep posting more
Killersmile · 24 weeks and 6 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this? is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.


Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: