Bash: It’s the little things

The “Bash (Bash – GNU Project)”:bash shell always amazes me. I needed to create a “Maildir (Wikipedia: Maildir)”: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 (Bash – GNU Project)”:bash man page and I discovered “Brace Expansion (Bash Reference Manual: Brace Expansion)”:brace:

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?

[maildir]http://en.wikipedia.org/wiki/Maildir
[brace]http://www.gnu.org/software/bash/manual/bashref.html#SEC27
[bash]http://www.gnu.org/software/bash/

One Reply to “Bash: It’s the little things”

Comments are closed.