文章目录
shell脚本
以下是一个简单的 Shell 脚本,用于在 Ubuntu 系统中打开和关闭网络代理开关
bash
#!/bin/bash
# 检查传入的参数
if [ "$#" -ne 1 ]; then
echo "Usage: $0 <1|0>"
echo "1: Enable proxy (set to manual)"
echo "0: Disable proxy"
exit 1
fi
# 根据参数设置代理模式
if [ "$1" -eq 1 ]; then
echo "Enabling manual proxy settings..."
gsettings set org.gnome.system.proxy mode 'manual'
echo "Manual proxy settings enabled."
elif [ "$1" -eq 0 ]; then
echo "Disabling proxy settings..."
gsettings set org.gnome.system.proxy mode 'none'
echo "Proxy settings disabled."
else
echo "Invalid argument: $1"
echo "Use 1 to enable proxy or 0 to disable proxy."
exit 1
fi
exit 0
使用说明
-
将上述代码保存为一个脚本文件,例如
proxy_toggle.sh
。 -
给脚本执行权限并拷贝至/usr/bin目录:
bashchmod +x proxy_toggle.sh sudo mv proxy_toggle.sh /usr/bin/proxy
验证设置
- 运行以下命令验证当前代理模式:
shell
$ proxy 1
Enabling manual proxy settings...
Manual proxy settings enabled.
shell
$ proxy 0
Disabling proxy settings...
Proxy settings disabled.