RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1410087 - bash searches $PATH only if the command is not already hashed
Summary: bash searches $PATH only if the command is not already hashed
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: bash
Version: 7.3
Hardware: Unspecified
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Siteshwar Vashisht
QA Contact: BaseOS QE - Apps
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2017-01-04 12:35 UTC by Marek Haicman
Modified: 2017-01-05 09:31 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2017-01-05 09:31:59 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Marek Haicman 2017-01-04 12:35:24 UTC
Description of problem:
When binary is available in more than one directory of $PATH, bash can get lost and stops running based on PATH variable, but still uses the same one.

Version-Release number of selected component (if applicable):
bash-4.2.46-21.el7_3.x86_64

How reproducible:
reliably

Steps to Reproduce:
create files a_1.sh and a_2.sh, which echoes 1 and 2 respectively:

Actual results:
[dahaic@dhcp-24-168 ~]$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/dahaic/.local/bin:/home/dahaic/bin
[dahaic@dhcp-24-168 ~]$ sudo cp a_1.sh /usr/bin/a.sh
[dahaic@dhcp-24-168 ~]$ a.sh
1
[dahaic@dhcp-24-168 ~]$ sudo cp a_2.sh /usr/local/bin/a.sh
[dahaic@dhcp-24-168 ~]$ a.sh
2
[dahaic@dhcp-24-168 ~]$ sudo rm /usr/local/bin/a.sh 
[dahaic@dhcp-24-168 ~]$ a.sh
1
[dahaic@dhcp-24-168 ~]$ sudo cp a_2.sh /usr/local/bin/a.sh

!!! it breaks !!!
[dahaic@dhcp-24-168 ~]$ a.sh
1
[dahaic@dhcp-24-168 ~]$ which a.sh
/usr/local/bin/a.sh
[dahaic@dhcp-24-168 ~]$ /usr/local/bin/a.sh 
2
[dahaic@dhcp-24-168 ~]$ a.sh
1

Expected results:
Binary reported by which is run by bash

Additional info:

Comment 1 Kamil Dudka 2017-01-04 12:58:55 UTC
(In reply to Marek Haicman from comment #0)
> Actual results:
> [dahaic@dhcp-24-168 ~]$ echo $PATH
> /usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/dahaic/.
> local/bin:/home/dahaic/bin
> [dahaic@dhcp-24-168 ~]$ sudo cp a_1.sh /usr/bin/a.sh
> [dahaic@dhcp-24-168 ~]$ a.sh
> 1
> [dahaic@dhcp-24-168 ~]$ sudo cp a_2.sh /usr/local/bin/a.sh
> [dahaic@dhcp-24-168 ~]$ a.sh
> 2

For me it already prints 1 in the above step, which is the documented behavior of bash -- see the bash(1) man page:

    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.

So just use the 'hash' built-in to update the hash table in cases like this.

Comment 2 Marek Haicman 2017-01-04 14:30:03 UTC
Thank you for the explanation, Kamil.

Can we at least ignore the hash table, when binary is not found in the location? It happened to me few times :)

[dahaic@dhcp-24-168 openscap]$ oscap --version
bash: /usr/bin/oscap: No such file or directory
[dahaic@dhcp-24-168 openscap]$ hash -r
[dahaic@dhcp-24-168 openscap]$ oscap --version
OpenSCAP command line tool (oscap) 1.2.13

Comment 3 Kamil Dudka 2017-01-04 15:28:31 UTC
(In reply to Marek Haicman from comment #2)
> Can we at least ignore the hash table, when binary is not found in the
> location?

It would contradict the current documentation for no real benefit.  Even if you convince upstream that it is a good idea, the behavior is not going to change in any released products.

> It happened to me few times :)

Given the fact that the hashing affects only the current session, it should not happen in usual workflows.  Why do you remove /usr/bin/oscap?

If you do it intentionally to force using oscap from a different location, then just invoke 'hash oscap' to make it explicit.

> [dahaic@dhcp-24-168 openscap]$ oscap --version
> bash: /usr/bin/oscap: No such file or directory
> [dahaic@dhcp-24-168 openscap]$ hash -r
> [dahaic@dhcp-24-168 openscap]$ oscap --version
> OpenSCAP command line tool (oscap) 1.2.13

Note that the hashing can also be disabled via 'set +h'.

Comment 4 Marek Haicman 2017-01-04 18:58:09 UTC
For posterity - I was doing make uninstall, to check whether version provided via RPM has the same error as the upstream version.

Even though it's not very transparent behaviour for someone not aware of the hashing, it does behave in documented way.

I have no more objections and we can close it as NOTABUG.

Comment 5 Kamil Dudka 2017-01-05 09:31:59 UTC
Thank you for clarifying it!  Closing...


Note You need to log in before you can comment on or make changes to this bug.