Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I hate when bash gives me "duh!" kind of error:

foo$ ./bar
-bash: ./bar: is a directory

I used to love AmigaOS shell in which "execution" of a directory simply meant setting it as the current directory:

foo$ ./bar

Is it possible in bash? (without infinite number of aliases of course.)

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Bash 4.0 has the autocd option.

From the Official FAQ:

There is a new 'autocd' option that, when enabled, causes bash to attempt to `cd' to a directory name that is supplied as the first word of a simple command.

Also, take a look at the CDPATH environment variable in man bash for any version since at least as early as 2.0. It allows you to shorten cd commands by searching the listed directories for the directory specified in a cd command.

share|improve this answer

Don't know about bash but this is possible in zsh.

# ~/.zshrc
setopt autocd

Edit: you could probably handle this in bash the same way ubuntu catches command not found

    # bashrc

    function command_not_found_handle {
            if [ -d $1]; then
                cd $1
                echo command not found
share|improve this answer
command_not_found_handle doesn't seem to do anything for me [GNU bash, version 3.2.17(1)-release (i386-apple-darwin9.0)] (tried .bashrc and .profile) – Kornel Aug 6 '09 at 23:45
I had quick google on this after i posted it, but i'm not sure how debian/ubuntu actually make that function work, unless they've modified bash to do it. – theotherreceive Aug 7 '09 at 1:59

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.