简体   繁体   English

条件语句 bash 配置文件中的 IP 地址

[英]IP address in condition statement bash profile

below ism y code低于 ism y 代码

if [ ip add show tun0 2>/dev/null ] ; then
    export http_proxy="http://127.0.0.1:2123"
fi

But when i do echo after conencting但是当我在连接后做回声时

echo $http_proxy

it is not displaying.它没有显示。 can advice?可以指教吗?

@GordonDavisson suggested: @GordonDavisson 建议:

if ip add show tun0 2>/dev/null
then
   export http_proxy='http://127.0.0.1:2123'
fi

but you could also write it like this:但你也可以这样写:

ip add show tun0 2>/dev/null && export http_proxy='http://127.0.0.1:2123'

ip will print stuff on stdout when successful, so maybe you want to do >& /dev/null ? ip成功时会在标准输出上打印东西,所以也许你想做>& /dev/null Instead of throwing all the data away, consider storing it in a variable, then you can always add a verbose flag to your program at some later point to print the content of that variable if you need to debug it.与其丢弃所有数据,不如考虑将其存储在一个变量中,然后您可以随时在程序中添加一个详细标志,以便在需要调试时打印该变量的内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM