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


2 Answers 2


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.

  • 1
    Great answer. Bash 4 is also available in MacPorts:subbing sudo port install bash into your step 1 works as well.
    – ephsmith
    Commented Jul 3, 2012 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 Commented Jul 9, 2012 at 2:51
  • @MichaelDurrant I edited the answer. bash -version would be the first version on $PATH. Did you try echo $BASH_VERSION?
    – Lri
    Commented Jul 9, 2012 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? Commented Jul 10, 2012 at 2:53
  • 1
    @MichaelDurrant Is your terminal application set to open with something like /usr/bin/login or login -fp $USER in the preferences?
    – Lri
    Commented Jul 10, 2012 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .