Upgrade bash to 4.0 in Mac OS X
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.$ 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.$ 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)-releasecoproc, 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.
July 8, 2009 9:45 AM
echo $BASH_VERSION
4.0.0(1)-release
but:
bash --version
GNU bash, version 2.05b.0(1)-release (powerpc-apple-darwin8.0)
how can it be? I have done everything as you.
thanks for the help.
July 23, 2009 3:36 AM
echo $BASH_VERSION
4.0.0(1)-release
but:
bash --version
GNU bash, version 2.05b.0(1)
How can it be? I did everything exactly as you.
thanks,
peter
April 5, 2010 3:48 AM
the install is failing at make:
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [bash] Error 1
can you help?
December 3, 2010 1:27 AM
+1, this works very well.
December 11, 2010 5:48 PM
You will need to shift around the paths found in /etc/paths in order to place /usr/local/bin ahead of /bin so that when executing bash --version it will find your newly installed shell.
I cannot see how this would adversely affect system stability since very few executables should be located within /usr/local/bin which take the place of system level binaries.