The PATH variable is a convenient mechanism for allowing organization and sharing of procedures. However, it must be used in a sensible fashion, or the result might be a great increase in system overhead.
The process of finding a command involves reading every directory included in every pathname that precedes the needed pathname in the current PATH variable. As an example, consider the effect of invoking nroff (that is, /usr/bin/nroff) when the value of PATH is :/bin:/usr/bin. The sequence of directories read is as follows:
. / /bin / /usr /usr/binA long path list assigned to PATH can increase this number significantly.
The vast majority of command executions are of commands found in /bin and in /usr/bin. Careless PATH setup can lead to unnecessary searching. The following three examples are ordered from worst to best with respect to the efficiency of command searches:
:/usr/john/bin:/usr/local/bin:/bin:/usr/bin :/bin:/usr/john/bin:/usr/local/bin:/usr/bin :/bin:/usr/bin:/usr/john/bin:/usr/local/binThe first one above should be avoided. The others are acceptable and the choice among them is dictated by the rate of change in the set of commands kept in /bin and /usr/bin.
A procedure that is expensive because it invokes many short-lived
commands can often be speeded up by setting the PATH
variable inside the procedure so that the fewest possible
directories are searched in an optimum order.