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 1768506 - /etc/profile.d/which2.sh incorrect if statement to catch ksh shell.
Summary: /etc/profile.d/which2.sh incorrect if statement to catch ksh shell.
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: which
Version: 8.0
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: 8.0
Assignee: Than Ngo
QA Contact: Jakub Haruda
URL:
Whiteboard:
: 1804801 (view as bug list)
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2019-11-04 15:49 UTC by Ryan Blakley
Modified: 2023-09-07 20:55 UTC (History)
3 users (show)

Fixed In Version: which-2.21-11.el8
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-04-28 16:55:04 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker RHELPLAN-29804 0 None None None 2023-09-02 14:00:04 UTC
Red Hat Product Errata RHBA-2020:1851 0 None None None 2020-04-28 16:55:05 UTC

Description Ryan Blakley 2019-11-04 15:49:11 UTC
Description of problem: The if statement in /etc/profile.d/which2.sh is incorrect, it only checks for ksh and not -ksh. So the wrong alias gets set on login shells.

Steps to Reproduce:
1. su to a user with ksh set as the login shell
2. Run $ which cat and error shows.

Actual results:
root@ryan-rhel8 ~ # su - ryan
Last login: Mon Nov  4 10:32:41 EST 2019 on pts/0
$ which cat
-ksh: declare: not found
/usr/bin/cat
$ exit

Expected results:
root@ryan-rhel8 ~ # su - ryan
Last login: Mon Nov  4 10:34:49 EST 2019 on pts/0
$ which cat
/usr/bin/cat
$ exit


Additional info:
- Looks like $0 returns a - in front of every shell, so it should be -ksh not ksh. 
root@ryan-rhel8 ~ # echo $0
-bash
root@ryan-rhel8 ~ # su - ryan
Last login: Mon Nov  4 10:34:28 EST 2019 on pts/0
$ echo $0
-ksh
$ exit

- The below patch fixes the issue on my test vm.
root@ryan-rhel8 ~ # diff -up which2.sh.old /etc/profile.d/which2.sh 
--- which2.sh.old	2019-11-04 10:29:15.213215270 -0500
+++ /etc/profile.d/which2.sh	2019-11-04 10:32:22.872103846 -0500
@@ -1,6 +1,6 @@
 # Initialization script for bash and sh
 
-if [ "$0" = ksh ] ; then
+if [ "$0" = "-ksh" ] ; then
   alias which='(alias; typeset -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
 else
   alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'

- Also I checked, and the if statement is the same on the latest F30 released package.

Comment 1 Than Ngo 2019-11-05 13:53:10 UTC
i also can reproduce this issue. Thanks for your report.

Comment 4 Ryan Blakley 2019-11-08 16:27:24 UTC
One correction, didn't catch that a non-login shell doesn't have the dash, so I updated the change to the below that works for login and non-login shells.

root@ryan-rhel8 ~ # diff -up which2.sh.old /etc/profile.d/which2.sh 
--- which2.sh.old	2019-11-08 11:24:56.981031433 -0500
+++ /etc/profile.d/which2.sh	2019-11-08 11:24:05.206401404 -0500
@@ -1,6 +1,6 @@
 # Initialization script for bash and sh
 
-if [ "$0" = ksh ] ; then
+if [ "$0" = "ksh" ] || [ "$0" = "-ksh" ]; then
   alias which='(alias; typeset -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'
 else
   alias which='(alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot'

Comment 5 Than Ngo 2019-11-19 09:29:53 UTC
it's fixed in which-2.21-11.el8

Comment 7 Than Ngo 2020-03-24 12:02:48 UTC
*** Bug 1804801 has been marked as a duplicate of this bug. ***

Comment 10 errata-xmlrpc 2020-04-28 16:55:04 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2020:1851


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