[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Env var feature request
From: |
Greg Wooledge |
Subject: |
Re: Env var feature request |
Date: |
Tue, 9 Jul 2024 16:28:01 -0400 |
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.