Bug 921213

Summary: PATH cache sticky
Product: [Fedora] Fedora Reporter: Bob Gustafson <bobgus>
Component: bashAssignee: Roman Rakus <rrakus>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: unspecified Docs Contact:
Priority: unspecified    
Version: 18CC: admiller, ooprala, rrakus, tsmetana
Target Milestone: ---   
Target Release: ---   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2013-03-14 14:16:01 UTC Type: Bug
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Bob Gustafson 2013-03-13 17:50:57 UTC
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:

Comment 1 Roman Rakus 2013-03-14 14:16:01 UTC
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...