0

I came across this question and showing the current path after cd is exactly what I'm looking for.

However, I can't manage to get this behavior.

What I've tried is this:

export CDPATH='.:/home/alexzeitler'

and

export CDPATH=$HOME

But after cd, the current path is not shown.

I want to use it using bash and zsh and a solution without alias or function is preferred (those are known).

4
  • You mean after cd alone without argument? That's meant to chdir() to your home directory, that's independant of $CDPATH. $CDPATH is only involved when cd is given relative paths. Commented Apr 25, 2024 at 14:15
  • 1
    Quite dangerous to export CDPATH as that could affect scripts that use cd. Commented Apr 25, 2024 at 14:16
  • See also the posixcd option in zsh for the path to be printed even by non-interactive invocations of zsh when $CDPATH is involved. Commented Apr 25, 2024 at 14:18
  • Note that cd(1p) states: "If a non-empty directory name from CDPATH is used, or if cd - is used, an absolute pathname of the new working directory shall be written to the standard output as follows: "%s\n", <new directory> Otherwise, there shall be no output." Other conditions described there make it so cd without arguments would never result in outputting the directory, regardless of CDPATH. Of course, cd with non-slash-prefixed arguments works; for example: cd; mkdir -p src; CDPATH=$HOME; cd src Commented May 7, 2024 at 13:20

0

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.