On Sun, Oct 31, 2021 at 2:15 PM Mike Jonkmans <bash...@jonkmans.nl> wrote: > PATH=/dev/null > command -p hostname > hostname # executes /bin/hostname via the hash table > > I agree with OP that the behaviour is a bug, or at least unwanted behaviour.
I'd say it's a feature, and a good one too. Not having to prefix each invocation of a utility with `command -p ' is a convenience if there's a lot of them. > > I could not find this in POSIX nor in the bash manual, but it seems true: > Assignment to PATH clears the hash table. > (Even when the value stays the same). It's in XCU 2.9.1.4: > Once a utility has been searched for and found (either as a result of this > specific search or as part of an unspecified shell start-up activity), an > implementation may remember its location and need not search for the > utility again unless the PA TH variable has been the subject of an assignment. > If the remembered location fails for a subsequent invocation, the shell shall > repeat the search to find the new location for the utility, if any.