Telling bash to step aside for zsh

So, let’s say that you want to change your shell to zsh, but fall back to bash if it isn’t available on whatever system you’re using. This is useful if you use something like NIS or LDAP with home directory NFS, since you’ll be sshing around and bringing your .bashrc with you everywhere. The solution is pretty simple – just add this to the bottom of your .bashrc:

hash zsh 2>&- && exec zsh

Update: This breaks X-windows. Need to figure out why…
Update: My esteemed colleague informed me that I should check for interactive shell, which is a dead give-away for X:

if [ ! -z $PS1 ]; then
  hash zsh 2>&- && exec zsh -l
fi


Leave a Reply

Your email address will not be published. Required fields are marked *