|
From: | Matthew Woehlke |
Subject: | Re: GNU bash, 3.00.15(1)-release, referenced cmd in cwd executes alternate cmd |
Date: | Thu, 04 Jan 2007 10:20:58 -0600 |
User-agent: | Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.9) Gecko/20061206 Thunderbird/1.5.0.9 Mnenhy/0.7.4.0 |
Bojan Land wrote:
Under what circumstances does the gnu-bash path hash differ from that of the $PATH variable? Why is it even possible for this difference to occur?
Because bash uses a hash to speed look-up of frequently used commands. The only way to (almost) always get the right command every time is to do a $PATH lookup every time, which would of course defeat the purpose of having a hash. At least, that's my guess.
Anyway you would still have a race condition e.g. if PATH is '/usr/local/bin:/usr/bin:/bin' and a program appears in e.g. /usr/local/bin right after bash checks there (and, say, ultimately finds the program in /bin). By the time bash fork()s and exec()s, it is using the "wrong" version. So there isn't really any way to "fix" the problem; the hash just puts the onus on the user to force a refresh when things change (and meanwhile reduces I/O).
-- Matthew Caution: keep out of reach of adults.
[Prev in Thread] | Current Thread | [Next in Thread] |