Home » Questions » Computers [ Ask a new question ]

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

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.

Asked by: Guest | Views: 419
Total answers/comments: 2
bert [Entry]

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

"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.)"