[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Customize the command resolution in bash?

From: Greg Wooledge
Subject: Re: Customize the command resolution in bash?
Date: Mon, 14 Nov 2011 08:30:33 -0500
User-agent: Mutt/

On Fri, Nov 11, 2011 at 03:31:02PM -0700, Eric Blake wrote:
> On 11/11/2011 03:23 PM, Peng Yu wrote:
> > I'm not aware if there is any cache mechanism
> > to save the run time (but even so, different terminals still can not
> > see the same cache, hence each terminal has the overhead to create the
> > cache).

Bash *does* cache paths.

imadev:~$ type comm
comm is /usr/bin/comm
imadev:~$ comm -?
comm: illegal option -- ?
usage: comm [ -[123] ] file1 file2
imadev:~$ type comm
comm is hashed (/usr/bin/comm)

> > When there are many files in PATH, it is going to slow down
> > the performance.

You mean directories?  Then put the most popular directories first.

> Bash isn't doing the resolution so much as libc (read 'man execvp')
> (well, technically, bash may be manually repeating some of the same
> resolution code as in execvp for other reasons, but the same principles
> apply).

Bash does indeed perform the PATH lookup itself in order to cache the

> If you want to search fewer directories, then nothing is stopping you from:
> mkdir ~/mycache
> for every executable you want cached:
>   ln -s executable ~/mycache/
> PATH=$HOME/mycache:$PATH

> Meanwhile, per POSIX, bash DOES provide hashing once it learns where an
> executable lives, so that future invocations can rely on the hash (the
> hash is invalidated when you assign to $PATH).  Read up on 'help hash'.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]