Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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"?

share|improve this question
add comment

3 Answers

up vote 8 down vote accepted

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

share|improve this answer
    
It's more than just an echo feature. check out rumour.biology.gatech.edu/Computers/cdpath.shtml –  DaveParillo Jan 3 '10 at 0:51
    
THANK YOU. Spent hours trying to figure out why a java program that was being called by a node.js script wasn't running. Turned out there was a shell script there somewhere and because my CDPATH was exported in my profile, output of $(cd directory && pwd) printed out /path/to/directory /path/to/directory. –  Igor Zevaka Feb 20 at 4:14
add comment

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

share|improve this answer
add comment

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.)
share|improve this answer
add comment

Your Answer

 
discard

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.