Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
$ echo $http_proxy

$ curl -v
* About to connect() to proxy
# Correct downloading

$ sudo echo $http_proxy

$sudo curl -v
# Hanging.

Last command doesn't use proxy. Why?

$curl -v

Is also working correctly.

share|improve this question
up vote 5 down vote accepted

This doesn't do what you think it does:

sudo echo $http_proxy

With that, $http_proxy is expanded by the shell before sudo gets called, so it picks up your own environment.

A plain su (without -, -l or --login) also keeps (most of) the environment intact, so the proxy settings are inherited.

sudo does not preserve the environment by default. You could try either:

sudo -E curl ...

(to preserve the whole environment, if you're allowed to do that), or

sudo http_proxy=$http_proxy curl ...

to only pass http_proxy along (safer).

share|improve this answer

Specify the host as:

  • a command line argument (-x)
  • on the command line (var=moo command)
  • or export it to your environment

    $ curl -x

    $ curl

    $ http_proxy= curl

    $ http_proxy=;  curl

    $ export http_proxy=;  curl

    $ http_proxy=;  sudo curl

    $ export http_proxy=;  sudo -E curl 

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .