Shell代理开关函数
如果经常需要在终端里临时开关代理,把函数放进 ~/.zshrc 或 ~/.bashrc 会很省事。
函数
function proxyon() {
export http_proxy="socks5://127.0.0.1:1080"
export https_proxy=$http_proxy
export all_proxy=$http_proxy
echo "proxy on $http_proxy"
}
function proxyoff() {
unset http_proxy https_proxy all_proxy
echo "proxy off"
}使用
proxyon
proxyoff说明
这类函数适合“当前 shell 会话临时走代理”,不会直接修改系统级网络设置。