Bug 2050996

Summary: CentOS 9 Stream: export -f from /etc/profile not supported when using ksh as login shell
Product: Red Hat Enterprise Linux 9 Reporter: Stefan Krüger <stadtkind2>
Component: whichAssignee: Than Ngo <than>
Status: CLOSED ERRATA QA Contact: Jakub Haruda <jharuda>
Severity: medium Docs Contact:
Priority: unspecified    
Version: CentOS StreamCC: bstinson, efedin, jharuda, jwboyer
Target Milestone: rcKeywords: Triaged
Target Release: 9.1Flags: pm-rhel: mirror+
Hardware: x86_64   
OS: Linux   
Whiteboard:
Fixed In Version: which-2.21-28.el9 Doc Type: No Doc Update
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2022-11-15 11:16:07 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 Stefan Krüger 2022-02-05 16:29:38 UTC
Description of problem:

The following error is shown on login when using ksh as the default shell:

```
/etc/profile[61]: .[293]: export: -f: unknown option
Usage: export [-p] [name[=value]...]
 Help: export [ --help | --man ] 2>&1
```

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

setup-2.13.7-6.el9.noarch
ksh-1.0.0~beta.1-2.el9.x86_64

How reproducible:

happens every time

Steps to Reproduce:
1. sudo dnf -y install ksh
2. sudo usermod -s /bin/ksh93 $(whoami)
3. logout and login again

Actual results:

see above

Expected results:

no "export -f" error, /etc/profile that works with ksh

Additional info:

Comment 1 Stefan Krüger 2022-03-21 20:08:37 UTC
The root cause is `/etc/profile.d/which2.sh` from package `which-2.21-27.el9.x86_64`:


```bash
[...]
which_opt="-f" # <--
which_shell="$(cat /proc/$$/comm)" # <-- yields ksh93 for ksh93 shell

if [ "$which_shell" = "ksh" ] || [ "$which_shell" = "mksh" ] || [ "$which_shell" = "zsh" ] ; then # "ksh" != "ksh93"
  which_declare="typeset -f"
  which_opt=""
fi

which ()
{
(alias; eval ${which_declare}) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@"
}

export which_declare
export ${which_opt} which
```

I guess the fix would be adding `|| [ "$which_shell" = "ksh93" ]`.

Comment 3 Than Ngo 2022-05-09 12:42:23 UTC
it is fixed in which-2.21-28.el9

Comment 8 errata-xmlrpc 2022-11-15 11:16:07 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 (which bug fix and enhancement update), 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-2022:8305