How do I turn of "auto-echo" in bash when I 'cd'?

I don't know when this started happening but now, every time I cd to a directory it echoes the path right before it changes directories. This happens when I log into a server but doesn't happen on my local machine. The server is running Linux. My local machine is running Mac OS X.

I searched the Google as well as looked at the bash man page but I couldn't find anything. My .bashrc/.bash_profile doesn't have anything related to 'cd' (that I know of).

How do I modify this "feature"?


Solution 1:

The shell auto-echoes because CDPATH is defined as an environment variable. If you UNSET CDPATH the default cd behavior will appear again.

Solution 2:

The above answer suggesting to unset CDPATH is probably the best. However, if you want CDPATH to remain active while cd-ing you can also use in your scripts something like:

cd /path/to/wherever > /dev/null

Solution 3:

Another option is to more permanently override the builtin cd with a bash function. I've found something like this effective when placed in your ~/.profile (or similar) file:

function cd() {
    if [ -z "$*" ]; then 
        destination=~
    else
        destination=$*
    fi
    builtin cd "${destination}" >/dev/null && ls
}
  • This preserves the use of cd without arguments to return to your home directory.
  • The >/dev/null is responsible for swallowing the folder name being echoed. (That echoing of the folder name is what breaks scripts that use FOO=$(cd $SOMEVAR && pwd) to save a full path to a variable.)
  • And finally; as written this function performs an automatic ls after changing directories. (Remove the && ls to stop that.)