Upgrading pip: a shell quirk
I stumbled across a confusing issue the other day when trying to upgrade pip.
Huh!? Why would pip --version
and `which pip` --version
return different things?
As it turns out, there was a linux shell feature working against me.
The shell maintains a hash table for the locations of executables so they don’t have to search through all files on each path in PATH
over and over again for the same executable.
For reference, here is the relevant section of the dash manpage (which I find more legible than the corresponding section of the bash manpage):
$ man dash ... hash -rv command ... The shell maintains a hash table which remembers the locations of commands. With no arguments whatsoever, the hash command prints out the contents of this table. Entries which have not been looked at since the last cd command are marked with an asterisk; it is possible for these entries to be invalid. With arguments, the hash command removes the specified commands from the hash table (unless they are functions) and then locates them. With the -v option, hash prints the locations of the com‐ mands as it finds them. The -r option causes the hash command to delete all the entries in the hash table except for functions.