Whenever I run which in bash with enabled 'unbound variable protection' (aka set -euE -o pipefail) I'm getting this: environment: line 1: _declare: unbound variable ----/etc/profile.d/which2.sh---- # Initialization script for bash, sh, mksh and ksh _declare="declare -f" _opt="-f" if [ "$0" = "ksh" ] || [ "$0" = "-ksh" ] || [ "$0" = "mksh" ] || [ "$0" = "-mksh" ] ; then _declare="typeset -f" _opt="" fi which () { (alias; eval ${_declare}) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@" } export ${_opt} which
Version in use: which-2.21-23.fc35.x86_64
Downgrade to version which-2.21-22.fc35.x86_64 solve the problem for now... --- which2.sh 2021-03-18 17:50:28.000000000 +0100 +++ which2.sh.bug 2021-03-23 19:49:12.579664153 +0100 @@ -1,11 +1,16 @@ # Initialization script for bash, sh, mksh and ksh + +_declare="declare -f" +_opt="-f" + +if [ "$0" = "ksh" ] || [ "$0" = "-ksh" ] || [ "$0" = "mksh" ] || [ "$0" = "-mksh" ] ; then + _declare="typeset -f" + _opt="" +fi + which () { - if [ "$0" = "ksh" -o "$0" = "-ksh" -o "$0" = "mksh" -o "$0" = "-mksh" ] ; then - (alias; typeset -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@ - export which - else - (alias; declare -f) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot $@ - export -f which - fi +(alias; eval ${_declare}) | /usr/bin/which --tty-only --read-alias --read-functions --show-tilde --show-dot "$@" } + +export ${_opt} which
The `export -f` introduced by the new script also throws errors with ZSH (not sure if I should open another bug or not). To reproduce: ``` podman run --rm -ti fedora:34 bash -c "dnf install -y which zsh; zsh" [skipping dnf output] /etc/profile.d/which2.sh:export:16: invalid option(s) [root@0fd8d9951815]/# ``` The export builtin in zsh doesn't have `-f` and in general doesn't support exporting functions
it's fixed in which-2.21-24.fc35.x86_64
Reopening as it still does not work: which-2.21-24.fc35.x86_64 still reports: environment: line 1: _declare: unbound variable Thus command cannot be used in strict bash environment.
*** Bug 1948033 has been marked as a duplicate of this bug. ***
I'm also seeing this issue using which-2.21-24.fc34.x86_64
For zsh the problem moved a bit since the fix by Than Ngo https://bugzilla.redhat.com/show_bug.cgi?id=1942153#c4, but zsh is still complaining. ``` podman run --rm -ti fedora:34 bash -c "dnf install -y which zsh; zsh" [skipping dnf output] basename: missing operand Try 'basename --help' for more information. /etc/profile.d/which2.sh:export:18: invalid option(s) ``` because $SHELL is not set to /usr/bin/zsh at that time. When I locally started zsh from a bash and printed SHELL, then $SHELL was still set to /bin/bash and the if clause did not work properly. Hence, then I got ``` zsh /etc/profile.d/which2.sh:export:18: invalid option(s) ``` (without the basename error).
could (In reply to Zdenek Kabelac from comment #5) > Reopening as it still does not work: > > which-2.21-24.fc35.x86_64 still reports: > > environment: line 1: _declare: unbound variable > > > Thus command cannot be used in strict bash environment. Zdenek, could you download and test new build ? https://koji.fedoraproject.org/koji/taskinfo?taskID=66715419 Thanks
(In reply to Than Ngo from comment #9) > could (In reply to Zdenek Kabelac from comment #5) > > Reopening as it still does not work: > > > > which-2.21-24.fc35.x86_64 still reports: > > > > environment: line 1: _declare: unbound variable > > > > > > Thus command cannot be used in strict bash environment. > > Zdenek, could you download and test new build ? > > https://koji.fedoraproject.org/koji/taskinfo?taskID=66715419 I've installed and checked some cases and it appears to be working for me.
Zdenek, thanks for the testing and feedback!
(In reply to Than Ngo from comment #11) > Zdenek, thanks for the testing and feedback! Thank you for fixing it. I can confirm it's working for the zsh case, too.
This also affects Fedora 34. The fix from Rawhide does not fix it completely for me. It still produces an error if "set -o pipefail" is used in addition to unbound variable checking. The following script reproduces the problem here: """ #!/usr/bin/bash set -uo pipefail which bash """ Running it results in the following output: """ environment: line 1: which_declare: unbound variable /usr/bin/bash """
(In reply to Simon Gerhards from comment #13) > This also affects Fedora 34. > > The fix from Rawhide does not fix it completely for me. It still produces an > error if "set -o pipefail" is used in addition to unbound variable checking. > > The following script reproduces the problem here: > """ > #!/usr/bin/bash > set -uo pipefail > which bash > """ > > Running it results in the following output: > """ > environment: line 1: which_declare: unbound variable > /usr/bin/bash > """ it's fixed in which-2.21-26.fc35, built in rawhide. Could you please test it? Thanks
FEDORA-2021-9c4af8a655 has been submitted as an update to Fedora 34. https://bodhi.fedoraproject.org/updates/FEDORA-2021-9c4af8a655
FEDORA-2021-9c4af8a655 has been pushed to the Fedora 34 testing repository. Soon you'll be able to install the update with the following command: `sudo dnf upgrade --enablerepo=updates-testing --advisory=FEDORA-2021-9c4af8a655` You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2021-9c4af8a655 See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.
FEDORA-2021-9c4af8a655 has been pushed to the Fedora 34 stable repository. If problem still persists, please make note of it in this bug report.
The fix works for me. Thanks!
I can confirm the fix as well. Thanks!