[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Env var feature request
From: |
Daniel Colascione |
Subject: |
Re: Env var feature request |
Date: |
Tue, 09 Jul 2024 16:34:27 -0400 |
Greg Wooledge <greg@wooledge.org> writes:
> On Tue, Jul 09, 2024 at 20:14:27 +0000, Erik Keever wrote:
>> A --debug-envvars flag which will, when passed to bash, catch every
>> time an environment variable is set and print the file/line that is
>> setting it. To restrict it, "--debug-envvars FOO,BAR" to catch only
>> instances of FOO or BAR being set.
>
> It's not *exactly* what you're asking for, but you can get most of
> this by invoking bash in xtrace mode with PS4 set to a custom value:
>
> PS4='+ $BASH_SOURCE:$FUNCNAME:$LINENO:' bash -ilxc : 2>&1 | grep WHATEVER
>
> That will show you where WHATEVER is being set during an interactive
> shell login, for example. Omit the "l" flag if you want to debug a
> non-login shell instead.
>
> Note that if bash is being run as UID 0, it will ignore PS4 coming from
> the environment, for security reasons. So, this only works as a non-root
> user.
That's a cool trick. It should be in the manual.