LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   Bash printing pwd after cd now that I set CDPATH (http://www.linuxquestions.org/questions/linux-software-2/bash-printing-pwd-after-cd-now-that-i-set-cdpath-777239/)

TiredOfThis 12-21-2009 11:14 AM

Bash printing pwd after cd now that I set CDPATH
 
Hi all,

I set my CDPATH variable in .bashrc. Now, whenever I cd into a directory, bash will print the full path of the directory I just cd'd into.

Example:
Code:

[nathanb@nathanb-box ~] cd doc
/u/nathanb/doc
[nathanb@nathanb-box ~/doc] cd spec
/u/nathanb/doc/spec
[nathanb@nathanb-box ~/doc/spec]

This is annoying and redundant. Is there any way to make it not do that (apart from editing the source myself, obviously)?

Thanks!

catkin 12-21-2009 11:44 AM

This seems to do the trick, might be worth a whirl
Code:

function my_cd {
    \cd "$@" >/dev/null
}
alias cd='my_cd'


David1357 12-21-2009 12:50 PM

Quote:

Originally Posted by TiredOfThis (Post 3800026)
This is annoying and redundant. Is there any way to make it not do that (apart from editing the source myself, obviously)?

Why don't use just use the features of the PS1 prompt:

Code:

export PS1='[\u@\h \w] '
will give you a prompt identical to what you are currently displaying in your post.

TiredOfThis 12-21-2009 01:10 PM

Quote:

Originally Posted by David1357 (Post 3800147)
Why don't use just use the features of the PS1 prompt:

Code:

export PS1='[\u@\h \w] '
will give you a prompt identical to what you are currently displaying in your post.

That's what my PS1 is set to. However, bash ALSO chooses to display the pwd after each cd when CDPATH is set.

David1357 12-21-2009 01:38 PM

Quote:

Originally Posted by TiredOfThis (Post 3800178)
That's what my PS1 is set to. However, bash ALSO chooses to display the pwd after each cd when CDPATH is set.

From the bash man page:
Code:

    If a non-empty directory name from CDPATH is used, or if - is the
    first argument, and  the  directory change is successful, the
    absolute pathname of the new working directory is written to the
    standard output.

So this is the expected behaviour. If you want to supress the output, you will have to use something like the hack catkin suggested.

TiredOfThis 12-21-2009 03:15 PM

I'm still hoping I can dig up some .bashrc config setting that will let me suppress this, but it's starting to look like the hack is the only way to go.


All times are GMT -5. The time now is 10:49 PM.