I’m working on a C application that has to walk $PATH to find full pathnames for binaries, and the only allowed dependency is glibc (i.e. no calling external programs like which). In the normal case, this just entails splitting getenv(“PATH”) by colons and checking each directory one by one, but I want to be sure I cover all of the possible corner cases. What gotchas should I look out for? In particular, are relative paths, paths starting with ~ meant to be expanded to $HOME, or paths containing the : char allowed?
Share
One thing that once surprised me is that the empty string in
PATHmeans the current directory. Two adjacent colons or a colon at the end or beginning ofPATHmeans the current directory is included. This is documented in man bash for instance.It also is in the POSIX specification.
So
All mean the current directory is in
PATH