[Cialug] $PATH command resolution

Matthew Nuzum newz at bearfruit.org
Wed Jan 6 22:20:19 CST 2010


> > 4) iterates through $PATH, in order, looking for the first executable
> foo.
>
> Yep.  The hash table is only an optimization.
>
>
 And the big gotcha is that . (current working directory) is not in the path
by default as it is in Windows or Dos.

So if you have an executable in your current directory called cat and you
type cat at the command line you'll actually run /bin/cat. If you want to
execute the cat in your local path you have to type ./cat.

There are some systems (Ubuntu is one) that have in the ~/.profile this
command:

# set PATH so it includes user's private bin if it exists
if [ -d "$HOME/bin" ] ; then
    PATH="$HOME/bin:$PATH"
fi

So you can mkdir ~/bin and put your own personal scripts there and it gets
pre-pended to the path so ~/bin/cat would get executed instead of /bin/cat.

-- 
Matthew Nuzum
newz2000 on freenode, skype, linkedin, identi.ca and twitter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/cialug/attachments/20100107/7754b3b2/attachment.htm 


More information about the Cialug mailing list