Bash – How to Determine Source of an Environment Variable

bashenvironment-variablesshell

I have a Linux instance that I set up some time ago. When I fire it up and log in as root there are some environment variables that I set up but I can't remember or find where they came from.

  • I've checked ~/.bash_profile, /etc/.bash_rc, and all the startup
    scripts.
  • I've run find and grep to no avail.

I feel like I must be forgetting to look in some place obvious. Is there a trick for figuring this out?

Best Answer

If you use the env command to display the variables, they should show up roughly in the order in which they were created. You can use this as a guide to if they were set by the system very early in the boot, or by a later .profile or other configuration file. In my experience, the set and export commands will sort their variables by alphabetical order, so that listing isn't as useful.

Related Question