SHINCHVEN'S HEXO

Quick proxy in bash

Count: 156Reading time: 1 min
2018/09/22 Share

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.
1
vim /usr/local/bin/ssproxy
  1. Compose a script to set proxy and run your normal commands.
1
2
3
#!/bin/bash
export all_proxy=<YOUR_PROXY_URL> # set all proxy
$* # run your commands
  1. Grant this file execute permission, so it could be used as a command in bash.
1
chmod +x /usr/local/bin/ssproxy
  1. Usage
1
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.
CATALOG
  1. 1. Create a file which will be used as a command in bash
  2. 2. How it works