Description of problem: While researching a different problem, I noticed that executable locations previously found using PATH and a relative pathname stick in a cache somewhere. If the 'found' executable is deleted or renamed, the previously resolved location of the executable is used (and fails) instead of re-resolving the location using the PATH and the relative name. Version-Release number of selected component (if applicable): # bash --version GNU bash, version 4.2.42(1)-release (x86_64-redhat-linux-gnu) How reproducible: Consistent until logout/login Steps to Reproduce: 1. make two executables that echo their absolute location in the file system. Such as - for /usr/bin/pathtest.sh #!/bin/bash echo "I am in /usr/bin/" and - for /usr/sbin/pathtest.sh #!/bin/bash echo "I am in /usr/sbin/" 2. execute the following commands: # echo $PATH /root/perl5/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin # which -a pathtest.sh /usr/sbin/pathtest.sh /usr/bin/pathtest.sh # pathtest.sh I am in /usr/sbin/ # mv /usr/sbin/pathtest.sh /usr/sbin/xpathtest.sh # which -a pathtest.sh /usr/bin/pathtest.sh # pathtest.sh -bash: /usr/sbin/pathtest.sh: No such file or directory # 3. Note that even though /usr/bin/pathtest.sh exists and is on a path within PATH, it is not found. Actual results: # which -a pathtest.sh /usr/bin/pathtest.sh # pathtest.sh -bash: /usr/sbin/pathtest.sh: No such file or directory Expected results: # pathtest.sh I am in /usr/bin/ Additional info:
Use `type' instead of `which'. Bash is using hashtable to remember executed files. There are several ways to clean table, don't use table at all...