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): 2.21-16.el8 How reproducible: Steps to Reproduce: 1. create a ksh script that uses #!/usr/bin/ksh 2. run script via cron Actual results: When the profiles get run you see export: -f: unknown option Expected results: run script without trying to 'declare -f' in the which2.sh profile Additional info: The problem is here - --- which_shell="$(cat /proc/$$/comm)" if [ "$which_shell" = "ksh" ] || [ "$which_shell" = "mksh" ] || [ "$which_shell" = "zsh" ] ; then which_declare="typeset -f" which_opt="" fi --- /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 #!/bin/ksh cat /proc/$$/comm $ ./test.ksh test.ksh $ ksh test.ksh ksh =======================
sadly i cannot reproduce your reported issue. It will help me a lot if you can provide working reproduce. Thanks
You bet! 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 ... Reinstalled: which-2.21-16.el8.x86_64 Complete! [jstroik@c8test ~]$ vim test.ksh [jstroik@c8test ~]$ chmod +x test.ksh [jstroik@c8test ~]$ cat test.ksh #!/bin/ksh echo "about to source /etc/profile" source /etc/profile echo "Sourced /etc/profile" [jstroik@c8test ~]$ ./test.ksh about to source /etc/profile ./test.ksh[3]: .[70]: .[19]: export: -f: unknown option Usage: export [-p] [name[=value]...] Sourced /etc/profile
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? Thanks
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: ============== #!/bin/zsh source /etc/profile cat /proc/$$/comm eval ${which_declare} ============== 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. https://access.redhat.com/errata/RHBA-2022:2067