Notable bash $PATH behavior trivia

bscott at ntisys.com bscott at ntisys.com
Thu Jan 2 21:37:16 EST 2003


On Thu, 2 Jan 2003, at 7:07pm, mod+gnhlug at std.com wrote:
> And why do you say that it's the "normal, expected" behavior?

  It makes sense if you think about it.  The algorithm used by PATH is
fairly simple: If a command you specify does not specify a path (i.e., does
not contain a slash), the shell tries putting each component of the PATH
variable in front of it.  So, if you have an empty component, then it tries
executing that command with nothing extra in front of it.  That system, as
always, treats that as relative to the current directory.

  An example may help.  Say your PATH is "/bin::/usr/bin".  Say you execute
the command "foo".  The shell will try these, in order:

	/bin/foo
	foo
	/usr/bin/foo

  I'll agree this is a potential "gotcha", and I think it would, perhaps, be
better if the shell checked for and ignored empty PATH components, but I'm
sure there's somebody in the world who depends on this behavior and would
complain if it was changed.

-- 
Ben Scott <bscott at ntisys.com>
| The opinions expressed in this message are those of the author and do not |
| necessarily represent the views or policy of any other person, entity or  |
| organization.  All information is provided without warranty of any kind.  |




More information about the gnhlug-discuss mailing list