---
title: "Quick proxy in bash"
date: 2018-09-22T15:14:36.000Z
author: Z.SHINCHVEN
tags: [Commandline, terminal]
canonical: https://atlassc.net/2018/09/23/quick-proxy-in-bash
---
Sometimes we need to use proxy in bash, but it is boring and inconvenient for us config and clear proxy for bash everytime when we need to use a proxy.

## Create a file which will be used as a command in bash

1. Create a file and save it in /usr/local/bin, so it will be added to $PATH after you grant it execute permission.

```bash
vim /usr/local/bin/ssproxy
```

2. Compose a script to set proxy and run your normal commands.

```bash
#!/bin/bash

# declare proxy url
PROXY=<YOUR_PROXY_URL>

# set proxy environment variable
export use_proxy=yes
export all_proxy=$PROXY
export http_proxy=$PROXY
export https_proxy=$PROXY

# run the command or script you pass in
```

3. Grant this file execute permission, so it could be used as a command in bash.

```bash
chmod +x /usr/local/bin/ssproxy
```

4. Usage

```bash
ssproxy <YOUR_NORMAL_COMMAND>
```

## How it works

- Create a new bash instance;
- Set proxy;
- Run your commands;
- This bash instance will end after your commands are done, so you don't have to clear your proxy config in your terminal.
