Bash the Cache

If you develop executable programs you probably invoke them from one location, then install them to another for ongoing use. And the moment you do that the bash hash cache will bite you.

The bash documentation says this:

If the name is neither a shell function nor a builtin, and contains no slashes, Bash searches each element of $PATH for a directory containing an executable file by that name. Bash uses a hash table to remember the full pathnames of executable files to avoid multiple PATH searches (see the description of hash in Bourne Shell Builtins). A full search of the directories in $PATH is performed only if the command is not found in the hash table. If the search is unsuccessful, the shell searches for a defined shell function named command_not_found_handle. If that function exists, it is invoked in a separate execution environment with the original command and the original command’s arguments as its arguments, and the function’s exit status becomes the exit status of that subshell. If that function is not defined, the shell prints an error message and returns an exit status of 127.

In order to get out of this mess, apply set +h in your bash startup files. And in order to recover from the damage imposed in the current shell, use hash -r.

What a misfeature.