Muffinresearch Labs by Stuart Colville

BASH: Using brace expansion | 0 Comments

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

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

GNU screen: open tab in current working directory|(1)

A nice trick for having screen open a new tab in the same directory as the one you’re currently in. To use it add it to your .screenrc

# Open new window in current dir.
bind c stuff "screen -X chdir \$PWD;screen^M"
bind ^c stuff "screen -X chdir \$PWD;screen^M"

Hat tip: mteckert on SuperUser.com

Ubuntu: add-apt-repository: command not found|(3)

When you’re using a minimal Ubuntu install if you find the ‘add-apt-repository’ command is missing (it’s useful for adding PPAs and other repositories), then simply run:

sudo apt-get install python-software-properties

Photos on Flickr

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