The Bourne Again shell manual says, of cd dir
:
[…] each directory name in
CDPATH
is searched for dir. […] If dir begins with a slash (/
), thenCDPATH
is not used.
The Z shell manual says, of cd arg
:
Otherwise, if arg begins with a slash, attempt to change to the directory given by arg.
If arg does not begin with a slash, the behaviour depends on whether the current directory
.
occurs in the list of directories contained in the shell parametercdpath
. […] If.
occurs incdpath
, thencdpath
is searched strictly in order so that.
is only tried at the appropriate point.
The POSIX Ordinary shell manual says, of CDPATH
:
Works the same way as
PATH
for those directories not beginning with/
incd
commands.
The Debian Almquist shell manual says, of cd
:
If […] the shell variable
CDPATH
is set and the directory name does not begin with a slash, then the directories listed inCDPATH
will be searched for the specified directory.
The '93 Korn shell manual says, of cd arg
:
If arg begins with a
/
then the search path is not used. Otherwise, each directory in the path is searched for arg.
The MirBSD Korn shell manual says, of CDPATH
:
It works the same way as
PATH
for those directories not beginning with/
incd
commands.
With the single exception of the '93 Korn shell, none of these are actually the case:
% export CDPATH=/tmp: % mkdir wibble /tmp/wibble % ksh93 -c 'cd ./wibble' /tmp/wibble % dash -c 'cd ./wibble ; pwd' /home/JdeBP/wibble % bash -c 'cd ./wibble ; pwd' /home/JdeBP/wibble % mksh -c 'cd ./wibble ; pwd' /home/JdeBP/wibble % lksh -c 'cd ./wibble ; pwd' /home/JdeBP/wibble % posh -c 'cd ./wibble ; pwd' /home/JdeBP/wibble % zsh -c 'cd ./wibble ; pwd' /home/JdeBP/wibble %
/tmp/./wibble
exists and is a directory, but only the '93 Korn shell is searching CDPATH
and finding it. The rest are not.
Why not?
Best Answer
Because the manuals are wrong.
The '93 Korn shell is wrong, too.
The 1997 Single Unix Specification says:
The 2016 Single Unix Specification says the same in a different, and slightly redundant, way:
None of the manuals mention the part about
.
and..
, but that is what every shell apart from the '93 Korn shell is actually doing, despite what their manuals say: