Whenever I open a terminal I have this variable set:

$ echo $http_proxy
http://127.0.0.1:8888/

Where is this variable being set? I've checked .bashrc, .bash_profile, /etc/bash.bashrc and /etc/environment and it's nowhere there?!

I've also looked at System Settings in the network section and the proxy is empty.


For bash run:

PS4='+$BASH_SOURCE> ' BASH_XTRACEFD=7 bash -xl 7> /tmp/mylog

then use

grep "http_proxy=" /tmp/mylog

to search for it.

You can also limit the search to /home and /etc for a better result:

$ grep "http_proxy=" /tmp/mylog | grep -e /home -e /etc
++/home/ravexina/.bashrc> http_proxy=http://test:80

which means it has been set in my ~/.bashrc.

source


According to essentially the duplicate of what you asked on Unix & Linux site, there are couple of ways to approach this problem:

  1. use env command and observe the order in which variables were created, and use preceding and next variables to get rough idea of where the variable may have come from
  2. wrap files which you try to investigate with set -x command in the beginning and end of the file to see what each file does; potentially those files are sourcing other files, and set -x should explicitly state where sourcing occurs
  3. Consider going through some of the files you may have in your home folder via find -type f -exec grep 'VARIABLE_NAME' {} \; or just grep -rI 'VARIABLE'. This is time consuming , so might not be the best result, but hey - if there's no easy methods, one shouldn't put aside the hard ones.
  4. Run strace -v -s 10000 -e execve,open,read bash and observer what is being read and what is the preceding open() call. This might be useful with 2&>1 > output_trace.txt redirection to read later and maybe grep. Source
  5. You mentioned .bashrc, .bash_profile, /etc/bash.bashrc and /etc/environment. You also need to check:

    • /etc/profile
    • /etc/profile.d/*
    • ~/.profile (only if you don't have a ~/.bash_profile)
    • ~/.bash_login
  6. According to Arch Wiki, some programs like wget use this variable. Check if you might have .wgetrc or /etc/wgetrc file. This might be set there, although where it gets sourced into bash is another mystery