Description of problem:
/etc/profile.d/which2.sh incorrectly tests for ksh (and mksh, zsh) shells, sets 'declare -f' instead of 'typeset -f'
Version-Release number of selected component (if applicable):
Steps to Reproduce:
1. create a ksh script that uses #!/usr/bin/ksh
2. run script via cron
When the profiles get run you see
export: -f: unknown option
run script without trying to 'declare -f' in the which2.sh profile
The problem is here -
if [ "$which_shell" = "ksh" ] || [ "$which_shell" = "mksh" ] || [ "$which_shell" = "zsh" ] ; then
/proc/$$/comm is the name of the command. If the script is "test.ksh" and called
directly it of course doesn't detect a ksh shell, it thinks the shell is "test.ksh".
Is kind of amazing how this passed automated tests? Maybe need to be some new tests.
A quick point of clarification: this isn't really cron related. If the script is passed to the interpreter (ksh <script>) then /etc/profile.d/which2.sh will behave as intended. However, if the script is marked as executable and invoked directly (./script) then /proc/$$/comm will contain the name of the script.
$ cat test.ksh
$ ksh test.ksh
sadly i cannot reproduce your reported issue. It will help me a lot if you can provide working reproduce.
The steps are below, including reinstalling which (our configuration management automatically replaces the file when it runs).
You'll need to source /etc/profile to invoke /etc/profile.d/which2.sh. You'd do this for non-interactive shells including cron tasks and cluster jobs in certain cases. For example, we use Lmod which requires setup via /etc/profile.d/ files.
Let me know if this helps and if you need any other info.
[jstroik@c8test ~]$ sudo dnf reinstall which
Duo two-factor login for jstroik
[jstroik@c8test ~]$ vim test.ksh
[jstroik@c8test ~]$ chmod +x test.ksh
[jstroik@c8test ~]$ cat test.ksh
echo "about to source /etc/profile"
echo "Sourced /etc/profile"
[jstroik@c8test ~]$ ./test.ksh
about to source /etc/profile
./test.ksh: .: .: export: -f: unknown option
Usage: export [-p] [name[=value]...]
thanks for the test, i can now reproduce this issue with above steps.
Could you please download https://than.fedorapeople.org/rhel8/which/which-2.21-17.el8.x86_64.rpm and test?
Yes - I confirm I no longer receive the error. Thank you.
Looking at the updated which2.sh if you have an example script like this:
You will get different results if you ./test.zsh vs 'zsh test.zsh' due to the way /proc/$$/comm resolves.
*** Bug 2060919 has been marked as a duplicate of this bug. ***
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.