3

I have used the Bash shopt cdable_vars option for years. When I cd to a destination that requires cdable_vars to resolve, the shell echoes my CWD before returning me to the prompt. When I cd to a destination that doesn't require a cdable_vars lookup (i.e. a correct, fully spelled subdirectory or an absolute path), the shell doesn't echo my CWD.

Is this the normal, (undocumented?) behavior of cdable_vars?

I faintly recall having activated this behavior at one point, because I liked being reminded that I had navigated to a cdable_var. Now I don't want it, but I can't figure out how to turn it off.

I use the cd builtin (no function or alias).

I do use a prompt command hook, but running with set -x shows that both the cd command and the echo happen before the prompt command runs.

Other places to look?

2
  • Is your CDPATH variable set? Commented Feb 24, 2017 at 17:02
  • No, the CDPATH environment variable isn't set. Commented Feb 24, 2017 at 17:27

1 Answer 1

2

I deal with this with the following ugly hack:

$ type -a cd
cd is aliased to `cd $1 >/dev/null'
cd is a shell builtin

In other words, add this line to your ~/.bashrc:

alias cd='cd >/dev/null' 
2
  • Evidently this is the default behavior, and my memory of having activated it is wrong. Commented Feb 24, 2017 at 18:29
  • 1
    @Chap I don't think so. At least, I couldn't reproduce this on my system (Arch, bash, version 4.4.12(1)). And yes, I did remove the alias before testing ;). I'm guessing you've also turned something else on (that's why I asked about CDPATH) but I can't think of what it might be. Commented Feb 24, 2017 at 18:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.