dimanche 10 juillet 2016

Bash compare operator always true

I'm trying to write a small script to compare my external ip (first three bytes) with the one below

#!/bin/bash
MYFILE=/home/me/.config/i3/pia
while true
do
    IP_EX=$(wget http://ipinfo.io/ip -qO - | cut -d"." -f1,2,3) 
    if [[ "$IP_EX"=="173.199.65" ]]
    then
        echo file created
        touch $MYFILE 
    else
        echo file deleted
        rm -f $MYFILE   
    fi
    echo sleeping
    sleep 4
done

This forever returns 'file created', and the else statement is never executed. This is the case EVEN if I replace the $IP_EX with "whatever".

Aucun commentaire:

Enregistrer un commentaire