Proxy_IP=192.168.1.10 Proxy_Port=7890 # Set System Proxy function xyon(){ export https_proxy=http://$Proxy_IP:$Proxy_Port export http_proxy=http://$Proxy_IP:$Proxy_Port export all_proxy=socks5://$Proxy_IP:$Proxy_Port echo -e "System Proxy is $Proxy_IP:$Proxy_Port" } # unSet System Proxy function xyoff(){ unset all_proxy unset https_proxy unset http_proxy echo -e "System Proxy is Disabled" } # Default Function is Set Proxy if [ $# != 0 ] then if [ $1 == 'off' ] then xyoff elif [ $1 == 'on' ] then xyon else echo "Please Input on or off!" fi else echo "Please input command." fi
调用脚本
1 2 3 4 5 6
chmod +x setproxy.sh # 因为父子shell的问题,使用source来使得脚本设置来修改当前父Shell环境变量 # 开启代理 source setproxy.sh on # 关闭代理 source setproxy.sh off