Note: This bug is displayed in read-only format because the product is no longer active in Red Hat Bugzilla.
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

Summary: /etc/profile.d/which2.sh incorrect if statement to catch ksh shell.
Product: Red Hat Enterprise Linux 8 Reporter: Ryan Blakley <rblakley>
Component: whichAssignee: Than Ngo <than>
Status: CLOSED ERRATA QA Contact: Jakub Haruda <jharuda>
Severity: medium Docs Contact:
Priority: unspecified    
Version: 8.0CC: djez, jharuda, mkenjale
Target Milestone: rcFlags: pm-rhel: mirror+
Target Release: 8.0   
Hardware: Unspecified   
OS: Unspecified   
Whiteboard:
Fixed In Version: which-2.21-11.el8 Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-04-28 16:55:04 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 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