Check bash version before trying shopt -s autocd.  Plus some comments.