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 2060919 - A ksh script that sources profile /etc/profile.d/which2.sh will lead to error export: -f: unknown option
Summary: A ksh script that sources profile /etc/profile.d/which2.sh will lead to error...
Keywords:
Status: CLOSED DUPLICATE of bug 2025709
Alias: None
Product: Red Hat Enterprise Linux 8
Classification: Red Hat
Component: which
Version: 8.5
Hardware: Unspecified
OS: Unspecified
unspecified
medium
Target Milestone: rc
: ---
Assignee: Than Ngo
QA Contact: CS System Management SST QE
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-03-04 14:33 UTC by Welterlen Benoit
Modified: 2022-03-21 14:18 UTC (History)
0 users

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2022-03-21 14:18:07 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-114540 0 None None None 2022-03-04 14:34:34 UTC

Description Welterlen Benoit 2022-03-04 14:33:24 UTC
Description of problem:
A ksh script that sources profile /etc/profile.d/which2.sh will lead to error export: -f: unknown option

Version-Release number of selected component (if applicable):
RHEL 8.5
which-2.21-16.el8.x86_64

How reproducible:
always

Steps to Reproduce:
1. create a a.sh ksh script that sources profile files:
2. cat a.sh
#!/bin/ksh
. /etc/profile
3. => ./a.sh[4]: .[20]: export: -f: unknown option


Actual results:
./a.sh[4]: .[20]: export: -f: unknown option

Expected results:
No error

Additional info:
From RHEL 8.4 to RHEL 8.5:

The file /etc/profile.d/which2.sh has been updated between version 2.21-12.el8 and 2.21-16.el8:

From:

# Initialization script for bash and sh
  
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'
fi

to 

# shellcheck shell=sh
# Initialization script for bash, sh, mksh and ksh

which_declare="declare -f"
which_opt="-f"
which_shell="$(cat /proc/$$/comm)"
which_shell=$0

if [ "$which_shell" = "ksh" ] || [ "$which_shell" = "mksh" ] || [ "$which_shell" = "zsh" ] ; then
  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

---

When the file is sourced from a script, the cat /proc/$$/comm is the name of the script, not the shell (a.sh), thus conditions for ksh are not met, and which_opt is by default "-f"

- One ugly workaround is to set the option only if shell = bash:
---
if [ "$which_shell" = "bash"  ] || [ "$which_shell" = "sh" ] ; then
  which_declare="declare -f"
  which_opt="-f"
fi
---

And let the default to nothing.

Thanks

Comment 1 Welterlen Benoit 2022-03-21 14:18:07 UTC

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


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