As referenced in this fine answer, POSIX systems have an external binary cd
in addition to the shell builtin. On OS X 10.8 it's /usr/bin/cd
. You can't use it like the builtin cd
since it exits immediately after changing its own working directory. What purpose does it serve?
POSIX – What is the Point of the ‘cd’ External Command?
cd-commandcommandposix
Best Answer
It serves primarily as making sure the POSIX tool-chest is available both inside and outside a shell (see the POSIX rationale for requiring those).
For
cd
, that is not tremendously useful but note thatcd
changes directories but has other side effects: it returns an exit status that helps determine whether you're able tochdir()
to that directory or not, and outputs a useful error message explaining why you can'tchdir()
when you can't.Example:
Another potential side-effect is the automounting of a directory.
On a few systems, most of the external commands for the standard shell builtins are implemented as a symlink to the same script that does:
That is start a shell and run the builtin in it.
Some other systems (like GNU), have utilities as true executable commands which can lead to confusions when the behavior differs from the shell builtin version.