When I use any command with sudo the environment variables are not there. For example after setting HTTP_PROXY the command wget
works fine without sudo
. However if I type sudo wget
it says it can't bypass the proxy setting.
相关问题
- Is shmid returned by shmget() unique across proces
- $ENV{$variable} in perl
- how to get running process information in java?
- Error building gcc 4.8.3 from source: libstdc++.so
- Why should we check WIFEXITED after wait in order
You can also combine the two
env_keep
statements in Ahmed Aswani's answer into a single statement like this:Defaults env_keep += "http_proxy https_proxy"
You should also consider specifying
env_keep
for only a single command like this:Defaults!/bin/[your_command] env_keep += "http_proxy https_proxy"
The trick is to add environment variables to
sudoers
file viasudo visudo
command and add these lines:taken from ArchLinux wiki.
For Ubuntu 14, you need to specify in separate lines as it returns the errors for multi-variable lines:
For individual variables you want to make available on a one off basis you can make it part of the command.
First you need to
export HTTP_PROXY
. Second, you need to readman sudo
carefully, and pay attention to the-E
flag. This works:Here is the quote from the man page: