Muffinresearch Labs by Stuart Colville

BASH: Using brace expansion | Comments (0)

Posted in Code, Linux/Unix on 22nd June 2009, 10:17 pm by Stuart

There’s a nice feature of BASH which is to use a comma delimited list of strings inside of curly braces to reduce the amount of typing:

here’s an example of using brace expansion to create log files for apache:

sudo touch {access,error}.log

Something seen less often is a blank entry like so:

cp foo{,.bck}

Which is shorthand for cp foo foo.bck. This is really useful when copying and moving files around using long paths. Using brace expansion can minimise the amount of typing and help avoid errors caused by typos too.

Another use of brace expansion since BASH v3.0 is the possibility of using ranges within the lists like so:

for foo in {1..10}
> do
> echo $foo
> done
1
2
3
4
5
6
7
8
9
10

Or alternatively with letters too:

echo {a..f}
a b c d e f

See the advanced bash scripting guide for more examples.

Post Tools

Comments: Add yours







XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>



Using Loggerhead with mod_wsgi|(0)

Here’s a post I wrote over on the Project Fondue Blog about our use of Loggerhead with mod_wsgi under Apache. Loggerhead is the rather nice branch viewer for bazaar branches as used on Launchpad.net.

If you’re not already subscribed to the Project Fondue blog feed then I can recommend it, as there should be some interesting posts coming out of there in the coming months (yes I’m unashamedly biased!).

Ubuntu: Turn off changing workspace with mouse wheel|(1)

I found the changing with the workspace with the mouse wheel really annoying. To disable it go to System => Preferences => CompizConfig (available if the compizconfig-settings-manager package is installed) and uncheck “Viewport Switcher” which is under the “Desktop” heading.

Photos on Flickr

© Copyright 2004-10 Stuart Colville, all rights reserved. May contain traces of Muffin. Powered by WordPress. Hosting by Slicehost.com This page was baked in 0.500s.