[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: hash not restored after running command -p
From: |
Chet Ramey |
Subject: |
Re: hash not restored after running command -p |
Date: |
Mon, 1 Nov 2021 14:11:03 -0400 |
User-agent: |
Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 |
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 chet@case.edu http://tiswww.cwru.edu/~chet/
Re: hash not restored after running command -p, Robert Elz, 2021/11/01