Archive for the ‘bash’ Category
bash path cache
All UNIX shells cache the command paths based on the contents of PATH enviromental variable. This can cause a problem if a cached path no longer exists. For example, you have a command “foo” installed in /usr/bin and /usr/local/bin. Your PATH variable is set to “/usr/local/bin:/usr/bin“.When you run “foo“, it is searched under each directory listed in PATH and the results are cached. In this case, the path “/usr/local/bin/foo” will be cached for “foo“.Now suppose you delete the command file “/usr/local/bin/foo“. You still have another copy in “/usr/bin/foo“. However, the next time you type “foo“, the shell will return an error such as this:
-bash: /usr/local/bin/foo: No such file or directory
To clear the cached path of foo command, you can run
$ PATH=$PATH
This basically resets the PATH variable, thereby clearing the cache. For bash shell, you might be able to do the same thing using
$ hash -r
Although, the previous method should also work for bash.