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 1804801 - Regression: ksh shell invoked as login shell, 'which' command gives error: "-ksh: declare: not found"
Summary: Regression: ksh shell invoked as login shell, 'which' command gives error: "-...
Keywords:
Status: CLOSED DUPLICATE of bug 1768506
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: which
Version: 8.1
Hardware: x86_64
OS: Linux
medium
medium
Target Milestone: rc
: 8.0
Assignee: Than Ngo
QA Contact: David Jež
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2020-02-19 16:31 UTC by mkenjale
Modified: 2023-09-07 21:57 UTC (History)
5 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2020-03-24 12:02:48 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description mkenjale 2020-02-19 16:31:01 UTC
Description of problem:

ksh shell invoked as login shell, 'which' command gives error: "-ksh: declare: not found"

Version-Release number of selected component (if applicable):

ksh-20120801-252.el8.x86_64

How reproducible:

Always


Steps to Reproduce:

1. Add new user "test" with default login shell as "ksh"

     # useradd test -s /bin/ksh

2. Switch to user "test"

     # su - test

3. Execute the "which" command with any binary

     $ which less

Actual results:

$ which less
-ksh: declare: not found
/usr/bin/less

Expected results:

$ which less
/usr/bin/less

Additional info:

[1] When switching to "test" user, I observed that "echo $0" shows "-ksh" 

     # su - test
     $ echo $0
     -ksh

[2] Now when checked /etc/profile.d/which2.sh, observed the if loop only checks for "$0" = ksh" and hence else is executed stating "-ksh: declare: not found"

[3] Here is the /etc/profile.d/which2.sh file content:

# cat /etc/profile.d/which2.sh
# Initialization script for bash and sh

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'
fi


[4] Now when the above file is modified(changed if condition), getting expected results.

# cat /etc/profile.d/which2.sh
# Initialization script for bash and sh

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'
fi

Comment 1 Kamil Dudka 2020-03-06 11:22:16 UTC
Thank you for tracking down the root cause!

I think that the script should recognize both "-ksh" and "ksh" as ksh.  However the script is not part of ksh, it is installed by which.

% rpm -qf /etc/profile.d/which2.sh
which-2.21-12.el8.x86_64

I am switching the component accordingly.

Comment 4 Than Ngo 2020-03-24 12:02:48 UTC

*** This bug has been marked as a duplicate of bug 1768506 ***


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