Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

For example if a directory 'blob' exists and I just type 'blob[return]' then the system cds into the blob directory for me.

In Linux (Ubuntu) I can add shopt -s autocd to my .bashrc file, but on OS X this gives an error: -bash: shopt: autocd: invalid shell option name

share|improve this question
up vote 17 down vote accepted

autocd was added in bash 4.0. You can install a newer version of bash with Homebrew and then change the default login shell with chsh:

brew install bash;echo /usr/local/bin/bash|sudo tee -a /etc/shells;chsh -s /usr/local/bin/bash

After you open a new login shell (or a tab by default in Terminal or iTerm 2), echo $BASH_VERSION should print something like 4.2.45(2)-release.

Terminal and iTerm 2 open new shells as login shells by default, so bash reads ~/.bash_profile but not ~/.bashrc. If you don't source ~/.bashrc from ~/.bash_profile or anything, add shopt -s autocd to ~/.bash_profile instead of ~/.bashrc.

share|improve this answer
Great answer. Bash 4 is also available in MacPorts:subbing sudo port install bash into your step 1 works as well. – ephsmith Jul 3 '12 at 17:39
I did the above. I ended up with bash 4.2.29 and I made the changes to /etc/shells and did the cssh but no joy – Michael Durrant Jul 9 '12 at 2:51
@MichaelDurrant I edited the answer. bash -version would be the first version on $PATH. Did you try echo $BASH_VERSION? – user495470 Jul 9 '12 at 4:44
it works if i run the command directly /usr/local/bin/bash - i get v4.2 but how do I make that my default shell for a new window? – Michael Durrant Jul 10 '12 at 2:53
@MichaelDurrant Is your terminal application set to open with something like /usr/bin/login or login -fp $USER in the preferences? – user495470 Jul 10 '12 at 12:02

The output of shopt -p can be of some help here. It prints a list of settable options. Sadly, on Lion, autocd is not one of them (see excerpt below).

Edit Lauri's answer above has a solution for updating your shell to include autocd

$ shopt -p
shopt -u cdable_vars
shopt -u cdspell
shopt -u checkhash
shopt -s checkwinsize
shopt -s cmdhist
shopt -u compat31
shopt -u dotglob
shopt -u execfail
shopt -s expand_aliases
shopt -u extdebug
shopt -u extglob
shopt -s extquote
shopt -u failglob
shopt -s force_fignore
shopt -u gnu_errfmt
shopt -u histappend
shopt -u histreedit
shopt -u histverify
shopt -s hostcomplete
shopt -u huponexit
shopt -s interactive_comments
shopt -u lithist
shopt -s login_shell
shopt -u mailwarn
shopt -u no_empty_cmd_completion
shopt -u nocaseglob
shopt -u nocasematch
shopt -u nullglob
shopt -s progcomp
shopt -s promptvars
shopt -u restricted_shell
shopt -u shift_verbose
shopt -s sourcepath
shopt -u xpg_echo
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.