Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

6
  • You found out that a script can't change the environment of the calling shell, except if you run it with source. Usually, the proxy variables are set globally in /etc/environment, but there is no magic - your shell sources /etc/environment when it starts up. Perhaps there are programs that read from /etc/environment directly, but that would depend on the program. Most programs just inspect the variables, I would guess. Commented May 10, 2021 at 2:01
  • I seem to be wrong thinking that the shell uses /etc/environment: superuser.com/questions/664169/…. In any case, which programs do you want to configure with http_proxy? Perhaps there are other ways to configure them. Commented May 10, 2021 at 2:07
  • You are successfully changing the WPAD file, so GUI browsers like firefox should automatically use the updated proxy setting. Changing the proxy for command-line programs and tools like lynx, curl, wget, etc is much harder. They can't use a PAC or WPAD file. You can't even change the environment variables in a process's parent process, let alone globally. And there's no way to tell a shell to re-source a file when it changes. The only thing you can do is to update /etc/environment (or some other file) and then remember to manually source that file in every shell that needs it. Commented May 10, 2021 at 7:15
  • Actually, you could probably do some nasty hackery with $PROMPT_COMMAND to source a file if it has changed...but that will slow down every shell prompt while it does that. On every command you run. And it won't effect already-running tools, it can only change the *_proxy variables when the prompt is displayed. And it would only work in bash, not ash/dash/zsh/ksh/etc (you could probable use $PS1 in those, but that's an even uglier hack). NOTE: source aka . does work in PROMPT_COMMAND...I wasn't sure, so I tested it with PROMPT_COMMAND=". /tmp/pc-test.sh". So, ugly but doable. Commented May 10, 2021 at 7:29
  • Just a note: There is no such thing as a "system wide" variable that gets updated with every change. When a process is stared, it receives a copy of it's parent processes environment at the time the process was started. After that, any changes to the environment do not affect any other copy. Similar to making a photocopy of a document and then writing on either does not make the writing appear on the copies or original. Commented May 10, 2021 at 21:29