3

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
5

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
  • 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 '14 at 15:02
  • I modified the question a little, my original question wasn't very clear. – Sandro Aug 22 '14 at 15:04
3

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'
  • 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 '14 at 15:18
2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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