Bug 1804801

Summary: Regression: ksh shell invoked as login shell, 'which' command gives error: "-ksh: declare: not found"
Product: Red Hat Enterprise Linux 8 Reporter: mkenjale
Component: whichAssignee: Than Ngo <than>
Status: CLOSED DUPLICATE QA Contact: David Jež <djez>
Severity: medium Docs Contact:
Priority: medium    
Version: 8.1CC: djez, fkrska, kdudka, prjagtap, rmetrich
Target Milestone: rc   
Target Release: 8.0   
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: If docs needed, set a value
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2020-03-24 12:02:48 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 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 ***