[PLUG] Way to disable command hashing in bash?

Mayuresh mayuresh at acm.org
Sat Apr 10 13:14:20 IST 2010


bash remembers the location you executed a command from in a hash table so
that it does not have to interpret the whole PATH variable when you have
to execute the same command the next time (in the same session).

This is usually good, though at times it can be annoying. E.g. if you have
a set up where there is a "standard (std)" location of a program and a
"development (dev)" location where you check out (or copy) the program for
modifications.

Unless you have checked out the program you'd like bash to pick it up from
"std" location while if you check it out, you'd like bash to pick it up
from "dev" location.

To achieve this we set the PATH variable such that the "dev" location is
ahead of "std" location in the PATH.

So far so good.

Now let's say we execute the program in a state where it is not checked
out into "dev". So it executes fine from "std" location.

Now you realize you need to make a change to it and you check it out to
"dev". Now because you already have executed it from "std" in _this_
session, bash won't pick up your "dev" copy even though "dev" is ahead in
the PATH (because of caching).


Now the "solutions" I know and am not particularly happy with are:

1. Use hash -r to remove the cache.

2. Open a new session every time you check out, so that you begin with
empty cache.

3. Write a script for check-out operation that will empty the cache.

Rather, I am looking for a way that will disable caching completely and I
won't have to remember to do any manual operation if I check out the
program.

(Note that, "set checkhash" is something whose description might look
close this issue. But it addresses a different issue, not this.)

Web searches show bash to have "-d" command line option that disables
cache, though I didn't find that working on my bash version 4.0.

The compatibility mode of bash with classical sh (+B option) also does not
seem to disable cache.

Mayuresh.




More information about the Plug-mail mailing list