3

Thanks to @ilkkachu I found a solution to this. I have posted it here and you can find it in the comments as well.

I want to unset one environment variable and I have searched all these places:

~/.bashrc
~/.profile
/etc/profile
/etc/environment
~/.bash_profile
/etc/bash.bashrc
/etc/profile.d/

As you can see, I have done my homework, but not only I can't find this specific environment variable, I am not able to find the majority of environment variables that env command shows either.

btw, I am using Debian 10.

PS:as this question has been asked numerous times on different forums, I guide anyone that has this question to use the function provided by @terdon in one of the answers. Unfortunately that doesn't solve my problem. But it definitely works in ordinary situations.

Masoud
  • 141

2 Answers2

4

I have a little bash function I use for this sort of thing:

grep_bash () 
{ 
    grep --color -H "$@" ~/.bashrc ~/.profile ~/.bash_profile ~/bash.login ~/.bash_aliases /etc/bash.bashrc /etc/profile /etc/profile.d/* /etc/environment 2> /dev/null
}

That will cover most (all?) files that are commonly used in the various Linux flavors I am familiar with. It includes ~/.bash_aliases which is an Ubuntu thing, as far as I know. It also includes some standard ones you didn't search through, most importantly the files under /etc/profile.d.

If that doesn't find your variable, then you are most likely sourcing another file from inside one of those listed above. You can grep for all lines that are sourcing files and then go through those as well:

grep_bash -E '(\.|source) ' 

That will list all lines where one of the files listed above is sourcing another, so your variable might be defined in one of the sourced files. Of course, any one of these sourced files might be sourcing others in turn, so you might need to go deeper, but this should do as a starting point.

terdon
  • 242,166
  • Thanks for your cool function. Unfortunately It couldn't find any of those env vars. I then used the extended version. It only contained a bunch of auto-completion files that I don't think are relevant. – Masoud Sep 27 '21 at 16:28
1

Thanks to @ilkkachu I found a solution to this.

In the last part of the answer, it says that it might have happened during the startup (not so usual), and when I searched for my variable with this command from the answer: find /etc -type f -exec grep -F THE_VAR {} + I found it.

polemon
  • 11,431
Masoud
  • 141