[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: When "set -u", "which" outputs environment: line 1: _declare: unboun
From: |
Eli Schwartz |
Subject: |
Re: When "set -u", "which" outputs environment: line 1: _declare: unbound |
Date: |
Fri, 9 Apr 2021 16:51:54 -0400 |
On 4/9/21 4:22 PM, Greg Wooledge wrote:
> On Fri, Apr 09, 2021 at 03:08:25PM -0400, Craig Andrews wrote:
>> Description:
>> With "set -u", invoking "which" results in the output of:
>> environment: line 1: _declare: unboundvariable
>> That should not happen, and does not happen, with prior versions of
>> bash.
>> I'm using Fedora 34 (beta).
>>
>> Repeat-By:
>> Run this shell script:
>> #!/bin/bash
>> set -u
>> echo "$(which bash)"
>>
>
> I can think of two possible reasons for this:
>
> 1) which(1) on your system is a bash script, and the error message is
> coming from that script.
>
> 2) which on your system is a shell function, which is somehow made visible
> to the script that you ran (possibly having been exported through the
> environment, or declared in a file that's loaded via BASH_ENV).
>
> Are you able to duplicate the error by running "which bash" in an
> interactive shell, or does it only happen in scripts?
>
> In whatever environment generates the error message, please run "type which"
> to find out exactly how which is defined.
>
> If it's a program (e.g. /usr/bin/which), please run "file" on that program
> to see whether it's a (bash) script.
>
> If it's a function, try to figure out where the function is being defined.
Are you ready to have your day truly spoiled? Fedora's package for the
external program GNU which, provides this /etc/profile.d/ script
(automatically injected into the environment of any interactive shell
sessions once you install GNU which -- how charming):
https://src.fedoraproject.org/rpms/which/blob/rawhide/f/which2.sh
Corresponding to the terrible advice from the GNU which manpage:
https://man.archlinux.org/man/which.1#EXAMPLE
So, it will on every `which` invocation feed the result of `alias;
declare -f` to ` | which --weird-options` and, essentially, reinvent
`type -a`.
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User
OpenPGP_signature
Description: OpenPGP digital signature
- When "set -u", "which" outputs environment: line 1: _declare: unbound, Craig Andrews, 2021/04/09
- Re: When "set -u", "which" outputs environment: line 1: _declare: unbound, konsolebox, 2021/04/09
- Re: When "set -u", "which" outputs environment: line 1: _declare: unbound, Greg Wooledge, 2021/04/09
- Re: When "set -u", "which" outputs environment: line 1: _declare: unbound,
Eli Schwartz <=
- Re: When "set -u", "which" outputs environment: line 1: _declare: unbound, Chet Ramey, 2021/04/09