Jump to content

Bash: cd sometimes echoing current directory

From FVue

Problem

Sometimes cd seems to echo the current directory, but other times it seems to do not?

Solution

If the CDPATH environment is set and the directory changing to is ambiguous (cd has multiple choices), the new directory will be echo'ed:

$ unset CDPATH  # Make sure CDPATH is unset
$ cd /
$ cd etc        # Goto unambiguous path.  Nothing is echo'ed
$ CDPATH=.
$ cd /
$ cd etc        # Goto ambiguous path (cd has to choose from etc or ./etc).  New dir is echo'ed
/etc
$

Environment

  • GNU bash, version 3.2.39(1)-release (i486-pc-linux-gnu)

Journal

20090121

Installation failure caused by CDPATH environment variable | KernelTrap
Forum thread about cd-behaviour causing Git install to fail