gpt4 book ai didi

shell - Ubuntu 中的 GNOME 代理开关

转载 作者:行者123 更新时间:2023-12-04 18:37:05 26 4
gpt4 key购买 nike

我使用 Ubuntu,而且我是 shell 脚本的新手。我尝试编写将在 Ubuntu GNOME 中切换代理模式的 shell 脚本。
对于每个开关,我都可以编写这样的脚本并使用启动器运行它。此命令将代理切换为无。

gconftool-2 -s -t string /system/proxy/mode none

这一个将代理模式切换为手动,我在工作中使用:
gconftool-2 -s -t string /system/proxy/mode manual

两者都有效,但我希望它们与 if-else 一起工作。我希望它检查当前的代理模式,如果当前的代理模式是 NONE,让它变成 MANUAL,否则如果当前的代理模式是 MANUAL,让它变成 NONE。如果我知道如何获取当前代理模式名称以在脚本中使用,我将能够构建此代码。

最佳答案

您只需要使用 -g 开关即可获取当前状态:

proxy_status=`gconftool-2 -g /system/proxy/mode`

if [ "$proxy_status" = "none" ]; then
# proxy is off
# do something clever
else
# proxy is on
# do something clever
fi

有了这个 bash 片段,你应该可以做任何你想做的事情:)

关于shell - Ubuntu 中的 GNOME 代理开关,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7485577/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com