bash 4.0 was released last month, and I'm only now getting around to messing with it. So far the things I use most are the '**' recursive globbing and the 'autocd' option. Here's how I upgraded my system and a few ways I use the new features.
- Download, build and install. Get the source tarball:
$ wget ftp://ftp.cwru.edu/pub/bash/bash-4.0.tar.gz
Build and install:
$ tar xzf bash-4.0.tar.gz
$ cd bash-4.0
$ ./configure && make && sudo make install
On my system (Leopard + Xcode) I had no trouble compiling. The binary is installed at /usr/local/bin/bash. You can also install via MacPorts or Fink, I imagine, but I try to do these things myself when possible, if only for the sake of transparency.
- Configure to use the new shell. First, register the new binary as a valid shell:
$ sudo bash -c "echo /usr/local/bin/bash >> /private/etc/shells"
Then change your user to use it as its shell with chsh (this is blatantly obvious, but modify the "Shell" line to point to /usr/local/bin/bash).
Now open a new shell (restarting Terminal.app will do, or just Cmd-N for a new window) and make sure your changes took:
[ian@iansmbp] ~/> echo $SHELL
/usr/local/bin/bash
[ian@iansmbp] ~/> echo $BASH_VERSION
4.0.0(1)-release
- Enable the new features. There's a bunch of features in the 4.0 release that I haven't gone through yet, including
coproc, improved programmable completion, a new &>> redirect operator (synonym of the old >>myfile 2>&1 pattern) and new case-insensitive expansion options. You can peruse a list of the new stuff at your leisure. For immediate gratification, however, just turn on recursive globbing and autocd:
$ echo "shopt -s globstar autocd" >> ~/.profile
$ source ~/.profile
** matches contents recursively. For example, where you might previously have recursively removed all your byte-compiled Python modules with:
$ find . -name \*.pyc | xargs rm -f
You can now simply:
$ rm -f **/*.pyc
If you've got a deep directory structure, and you want to get into a subdirectory whose name you know, you can replace:
$ cd path/to/the/directory/i/want/named/mydir
with:
$ cd **/mydir
Hey, and if those extra three characters at the beginning of that last command are too much for you, then you'll love the autocd option, which, when enabled, permits you to cd to a directory merely by typing its name:
[ian@iansmbp] ~/src/zenoss/core/Products/> **/yui
cd ZenWidgets/skins/zenui/yui
[ian@iansmbp] ~/src/zenoss/core/Products/ZenWidgets/skins/zenui/yui/>
More on new features as warranted; these two, however, are those of zsh that I missed most.
Read More...