'IP address in condition statement bash profile
below ism y code
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?
Solution 1:[1]
@GordonDavisson suggested:
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
? 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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |