Brace Yourself For Expansion

| No TrackBacks
SVG Icons * Bluesphere Icon Theme

SVG Icons * Bluesphere Icon Theme (Photo credit: Wikipedia)

So I am, once again Scratching That Itch and am playing with Linux From Scratch (more reports to come). But I came across an interesting bash syntax in the online manual and I had to investigate it further.

In the expect build section, they write about creating a backup of the configure script, and they do it thusly:
$ cp -v configure{,.orig}
This is the same thing as:
$ cp -v configure configure.orig
And so I had to look at it a bit. I came across a section in the man page about brace expansion, where you can generate arbitrary strings using a common prefix and/or suffix, so:

$ echo a{d,c,b}e 
ade ace abe
In the above 'cp' command, they are pass two parameters to cp, one without a suffix and one with the suffix of '.orig'. That's pretty cool, although I can't imagine ever remembering to do it! I would usually just use tab completion to do most of the heavy lifting for me:

$ cp -v confi<TAB> confi<TAB>.orig
But the methods could be combined and save a few keystrokes, esp. if there were multiple files that started with "confi".

Bash Reference Manual

Enhanced by Zemanta

No TrackBacks

TrackBack URL:

About this Entry

This page contains a single entry by Jonathan published on March 27, 2014 5:08 PM.

Getting The Right Sound was the previous entry in this blog.

Find recent content on the main index or look in the archives to find all content.