A reader made an interesting comment in reply to an old post. I had experienced some problems running a make file included with the sample code for Joe Armstrong’s Programming Erlang.
Gijsbert de Haan wrote:
About your directory troubles, you might have to unset CDPATH. I have never taken the time to figure out why, but make and CDPATH don’t go well together (it’s like make/shell forgets to look in the current directory when it has a CDPATH.
I have not had a chance to look into it, but that sounds very plausible. Recorded for posterity. Thank you, Gijsbert.

Posts
Well-defined behavior. Just as PATH=… with no current directory will not search the current directory for command invocation candidates, a CDPATH without a “.’ (current directory) entry will not search the current directory for candidate directory entries. There is an explicit equivalence that no CDPATH variable is interpreted as ‘CDPATH=.’ in any way that matters.
Without this explicit behavior, e.g. with an implicit search of the current directory, would it be less astonishing to search the current directory before, or after, the CDPATH?
There are a number of other reasons for this including keeping people from walking a directory tree in a restricted shell and such.
If you look in “man bash” you will see the sample value is ‘.:~:/usr’, and I believe that in most cases checking the current directory first is the best behavior, it prevents masking of directory classes. For instance if you had ‘CDPATH=/usr:.’ and you were in /usr/local then ‘cd bin’ would take you to /usr/bin instead of the expected /usr/local/bin, and so on.
August 4, 2008 @ 12:30 pm