As so often happens, there are two separate issues here - and the responders all seem to be missing the OP's point (which is #1 in the list below) and instead obsessing on #2 below.
The issues are:
1) I need help with my shell scripting. In particular, I need to learn how to quote my variables.
2) What is the best way to use external servers to determine my "WAN IP address"?
Now, it turns out that these issues are related, in that if the OP had a reliable method of getting the IP address - and only
the IP address into a shell variable, then the first issue wouldn't arise, but that doesn't negate the fact that the real issue here is that he is pretty new to shell scripting.
Anyway, addressing #2 first, it seems to me that the best way to get the iP (and only
the IP) is:
Note, FWIW, that another way to do it is to connect to an FTP site (pretty much any old FTP site will do) and do "quote stat".
Now, addressing #1:
If you want to do it with an "if" statement, you should do:
if [ "$IP" = "w.x.y.z" ]
That usually makes the weird error messages go away.
Or, you can use "case", like:
case $IP in
*w.x.y.z*) echo Yaman!;;
*) echo Nope;;
The nice thing about 'case', is that, almost as if by magic, quoting is not needed.
P.S. Finally, note that like the other responders on this thread, I wasn't able to get the "whatismyip.com" thing to work at all. In fact, I had spent some time messing with that company some time ago (on a totally unrelated matter) and I pretty much concluded that they had made themselves automation-proof. YMMV (of course).
And some folks need to stop being fanboys and see the forest behind the trees.
(One of the best lines I've seen on this board lately)