I'm having an issue with string comparisons in bash: the following sample is telling me the two strings being compared are different. they are not.
REMOTE=`grep remote /etc/hosts|cut -f1| tr -d ' '`
IP1=`/opt/local/bin/lynx -accept_all_cookies -dump
http://whatismyip.com | grep "Your IP Address Is"| cut -d" " -f8 |
tr -d ' '`
if [ "$IP1"<>"$REMOTE" ]
then
echo "IP1 -ne REMOTE"
echo "=>"$IP1"<="
echo "=>"$REMOTE"<="
sudo cp /etc/hosts /etc/hosts.bkp
sudo gsed -i 's/$IP/$REMOTE/g' /etc/hosts
fi
IP1 68.49.172.18
REMOTE 68.49.172.18
IP1 -ne REMOTE
=>68.49.172.18<=
=>69.49.172.18<=
if [ "$IP1"<>"$REMOTE" ]
The not equal operator is !=
, and you need spaces on both sides. They're not just for looks, they're required.
if [ "$IP1" != "$REMOTE" ]
if [ "$IP1"<>"$REMOTE" ]
Change this to:
if [ "$IP1" != "$REMOTE" ]
I think the string comparison operator in bash is != and not <>. Can you make a test to see if that is the problem you are having?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With