2

Just switched from tcsh to bash 4.2 on OSX, and autocd was what allowed me to do it. But it seems that by default if you type the name of a directory that also happens to be the name of an executable in my path, autocd is not invoked and the command is run.

Is there a way to change this behavior, so that it assumes I want to be safe and cd into the directory specified?

2
  • 1
    How about getting into the habit of always typing a slash at the end when you mean a directory? /tmp/ is still two characters shorter than cd /tmp, and it's unambiguous.
    – Mikel
    Mar 11, 2014 at 22:03
  • @Mikel this is basically what I have been doing ;)
    – notbrain
    Mar 13, 2014 at 0:05

1 Answer 1

4

You probably can't, which points to an underlying problem concerning why a feature such as autocd can never become standard: it introduces ambiguity. If you switched the behavior: how would you launch a program that is named the same as a currently available subdirectory? It becomes non-deterministic, which is the worst thing a UI can become, imho (and even worse for non-interactive shells, but that is avoidable by simply only setting autocd for interactive shells).

When I say "you probably can't", I mean that I looked through the shopt section of man bash and did not find any such modifier. One can of course fix it by e.g. modifying Bash's source, but I guess your question concerned an available setting to fix this for you.

1
  • good point about how would you ever run a command named the same as a directory if this was in fact possible, definitely not ideal for non-interactive shells. I don't recall the syntax offhand, but I assume it would be similar to how you bypass any aliases you've created to protect yourself from rm -rf * and the like.
    – notbrain
    Mar 13, 2014 at 0:09

You must log in to answer this question.

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