How can I find out where an environment variable (like PATH) was set?

I have a xterm with the bash shell in linux. When I echo $PATH, it is showing a directory and I want to know who put this directory in the PATH. How can I find out?

Thanks!


Solution 1:

Assuming your login shell is bash, you could start looking in the following files: /etc/profile, ~/.bashrc and ~/.bash_profile. If you invoke bash from another shell, then you might need to check what variables the other shell sets.

Solution 2:

You probably cannot discover who, but you can find out which file is setting that. Look a the Bash documentation for the startup files. There are several that bash processes on startup to set $PATH and the other environment variables.

http://www.gnu.org/software/bash/manual/html_node/Bash-Startup-Files.html#Bash-Startup-Files