On 11/1/21 11:26 AM, Chet Ramey wrote: > On 10/31/21 12:06 PM, Roger Morris wrote: >> Thanks for the reply. Though POSIX may allow this, still the last >> line of the following example is rather unexpected behavior >> >> $ >> $ echo echo MY LOCAL tmp/date SCRIPT > tmp/date >> $ chmod +x tmp/date >> $ >> $ PATH=.:/bin >> $ date >> Sun 31 Oct 2021 11:59:07 AM EDT >> $ hash -l >> builtin hash -p /bin/date date >> $ cd tmp ; date ; cd .. >> MY LOCAL tmp/date SCRIPT > > This seems weird and non-intuitive (why not use the hashed value?), but > it's actually a special case that's handled explicitly in the code. If the > PATH search that results in a value being put into the hash table finds `.' > in the PATH before finding the full path, the hash table remembers that > fact and -- as a special case -- checks whether `./name' is an executable > file before returning the hashed value on subsequent lookups. It's strange, > but everyone seems to do it.
Before we all pile on here, yes, I understand why we all do it. I still think it's non-intuitive, but you have to behave as if the hash table weren't there at all. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/