Bash: It’s the little things

The Bash shell always amazes me. I needed to create a Maildir using the typical Maildir/cur, Maildir/new, Maildir/tmp structure and stumbled on this:

$ mkdir -m 0700 -p Maildir/{cur,new,tmp}

The -m and -p options are no-brainers, but the {cur,new,tmp} was new to me. It was easy to figure out what was going to happen… one command to create the Maildir directory, and the three subdirectories, I was simply unfamiliar with the syntax. A quick look at the Bash man page and I discovered Brace Expansion:

Brace expansion is a mechanism by which arbitrary strings may be generated.

A comma separated list between opening and closing braces is expanded by the shell including any preamble (in my case Maildir/) or postscript. Brace expansion can also generate ranges:

$ echo {1..10}
1 2 3 4 5 6 7 8 9 10

Cool, huh?

This website uses IntenseDebate comments, but they are not currently loaded because either your browser doesn't support JavaScript, or they didn't load fast enough.

2 Responses to “Bash: It’s the little things”
  1. seang 28 June 2007 at 8:53 am #

    That is cool. I wish I had a use for it! ;-)

  2. seang 28 June 2007 at 7:53 am #

    That is cool. I wish I had a use for it! ;-)

Leave a Reply