Question: I have several network locations set up on my laptop: Work, Home, etc. The work one(s) all have a proxy server set up, while the others don't. This works fine for OSX applications -- Safari, Mail, even Firefox and Thunderbird with the [System Proxy](http://systemproxy.mozdev.org/) plugin.

For terminal applications such as `git`, `svn`, `gem`, and `curl` I have the following in my `.bash_profile`:

```
export HTTP_PROXY='http://proxy.mycompany.com:80'
export http_proxy=$HTTP_PROXY

```

My question is this: is there some way to make the exported variable look up the value from my system's current location? I'd prefer it to be done dynamically (so if I change locations during a terminal session it will change), but I'd be happy with just one that set it when `.bash_profile` ran (meaning I'd have to start a new terminal session when I changed locations).

Thanks!

Answer: 
In the [answer above](https://superuser.com/a/98976/24010), there is a [comment](https://superuser.com/questions/48480/how-can-i-get-mac-os-xs-proxy-information-in-a-bash-script#comment287602_98976) from [tlrobinson](https://superuser.com/users/78682/tlrobinson) about how it doesn't include the port number.

You can do that by switching out **HTTP Proxy Server** with **HTTP Proxy Port**

I have also seen this done like this:

```
system_profiler SPNetworkDataType | grep "HTTP Proxy Server" | awk '{print $4}' | head -1
system_profiler SPNetworkDataType | grep "HTTP Proxy Port" | awk '{print $4}' | head -1

```
You could use the [little tool](https://github.com/janvogt/export-proxies) I wrote, that sets the commonly used environment variables for proxies. Usage is straightforward:

1. Compile it with xCode.
2. Add:

```
eval `./path/to/export-proxies`

```

to your `.profile`, `.bashrc`, or `.bash_profile`.

After that you can use variables like `$HTTP_PROXY`, `$http_proxy`, `$HttpProxy`, etc. for all protocols (HTTP, FTP, SOCKS) including the `$NO_PROXY` exceptions. This will work for most CLI tool and gets the settings from the OS X control panel.