Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash: which <app> returns different location than expected

Tags:

bash

macos

Can anyone explain to me why the following is happening?

[$] pip
-bash: /usr/local/bin/pip: No such file or directory
[$] which pip
/bin/pip
like image 655
imagineerThat Avatar asked Dec 06 '25 08:12

imagineerThat


1 Answers

Application lookups are cached. Reset the pip entry:

hash pip

Quoting man bash:

If the name is neither a shell function nor a builtin, and contains no slashes, bash searches each element of the PATH for a directory containing an executable file by that name. Bash uses a hash table to remember the full pathnames of executable files (see hash under SHELL BUILTIN COMMANDS below). A full search of the directories in PATH is performed only if the command is not found in the hash table.

and the entry for hash in the same documentation:

hash [-lr] [-p filename] [-dt] [name]
For each name, the full file name of the command is determined by searching the directories in $PATH and remembered.

which always searches your path regardless of the hash entry.

like image 66
Martijn Pieters Avatar answered Dec 07 '25 21:12

Martijn Pieters



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!