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.
DescriptionWelterlen 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
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