C0p*_*t0p 5 string ip bash comparison
我在bash中遇到字符串比较的问题:下面的示例告诉我正在比较的两个字符串是不同的.他们不是.
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" ]
不等于运算符!=,并且您需要两侧都有空格.它们不仅仅是外表,它们是必需的.
if [ "$IP1" != "$REMOTE" ]