Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there a way to show the expanded version of a brace expansion statement?

For example, I have:

$ bundle exec rake db:{drop,create,migrate}

Does the expanded version expand to this?

$ bundle exec rake db:drop
$ bundle exec rake db:create
$ bundle exec rake db:migrate
share|improve this question

3 Answers 3

Well, you could always just do

~  for i (drop create migrate) echo bundle exec rake db:$i
bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate

Or

~ echo bundle exec rake db:{drop,create,migrate}
bundle exec rake db:drop db:create db:migrate
share|improve this answer
    
The second answer is what I wanted to see. I thought it expanded the longer version with three separate statements instead of your single statement. Thanks! –  Sandro Aug 22 at 15:02
    
I modified the question a little, my original question wasn't very clear. –  Sandro Aug 22 at 15:04

For it show as those 3 lines, you'd need:

$ print -rl 'bundle exec rake db:'{drop,create,migrate}
bundle exec rake db:drop
bundle exec rake db:create
bundle exec rake db:migrate

x{a,b}y creates 2 arguments where {a,b} is replaced with a in the first and b in the second.

If you wanted the above to be executed, you could pipe it to sh (or zsh though there's no zsh specific code in it), or you could write:

eval 'bundle exec rake db:'{drop,create,migrate}$'\n'
share|improve this answer
    
Thanks! I was also able to pipe it like so and it worked as well. print -rl 'bundle exec rake db:'{drop,create,migrate} | zsh –  Sandro Aug 22 at 15:18

No, it's expanded to:

bundle exec rake db:drop db:create db:migrate

From zsh documentation, braces expansion section:

A string of the form ‘foo{xx,yy,zz}bar’ is expanded to the individual words ‘fooxxbar’, ‘fooyybar’ and ‘foozzbar’. Left-to-right order is preserved. This construct may be nested. Commas may be quoted in order to include them literally in a word.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.