The original Bourne shell (
/bin/sh) did not have
CDPATH. That was one of the innovations of the Kornshell which was later added to the POSIX standard and then to bash itself. How it's implemented my differ from shell to shell and the mode that shell is in.
On many systems,
/bin/sh is a hard link to
/bin/bash, but bash changes its behavior when invoked as
sh instead of
bash. From the bash manpage:
If bash is invoked with the name sh, it tries to mimic the startup behavior of historical versions of sh as closely as possible, while conforming to the POSIX standard as well. When invoked as an interactive login shell, or a non-interactive shell with the --login option, it first attempts to read and execute commands from /etc/profile and ~/.profile, in that order.
On some systems,
/bin/sh is actually the dash` shell which descended from the ash shell.
So, the difference you're seeing may be due to the way bash works when being bash, bash works when it's operating in POSIX compatibility mode, or the fact you're using
ash instead of
bash which may or may not implement CDPATH in it's own unique way.
When using a POSIX compatible shell, the
. directory is not automatically included in
CDPATH. However, if a shell isn't completely POSIX compliant, it may automatically include
. in CDPATH for you.
I found this bit of info on Softpanorama:
Warning: Watch out when running bash in POSIX mode (e.g., as /bin/sh or with --posix). As the bash Reference notes:"If $CDPATH is set, the cd built-in will not implicitly append the current directory to it. This means that cd will fail if no valid directory name can be constructed from any of the entries in $CDPATH, even if a directory with the same name as the name given as an argument to cd exists in the current directory.
"To avoid this, explicitly include . in $CDPATH. However, if you do that, then another subtle point noted in the bash Reference comes into play:"If a nonempty 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."In other words, pretty much every time you use cd it will echo the new path to STDOUT, which is not the standard behavior.