[Cialug] $PATH command resolution

Jeffrey Ollie jeff at ocjtech.us
Wed Jan 6 22:00:33 CST 2010


On Wed, Jan 6, 2010 at 9:54 PM, Colin Burnett <cmlburnett at gmail.com> wrote:
> From the bash man page:
>
> `If the name is neither a shell function nor a builtin, and contains
> no slashes, bash searches each element of the PATH for a directory
> containing an  executable  file  by  that name.  Bash uses a hash
> table to remember the full pathnames of executable files.  A full
> search of the directories in PATH is performed only if the command is
> not found in the hash table.`
>
> I interpret that to mean if you call foo from /a/b/c then it
> 1) looks for /a/foo
> 2) looks for /a/b/foo
> 3) looks for /a/b/c/foo

Bash will not look in any of these directories.

> 4) iterates through $PATH, in order, looking for the first executable foo.

Yep.  The hash table is only an optimization.

-- 
Jeff Ollie


More information about the Cialug mailing list