2

I'm trying to create simple script to check whether my external ip address has changed. However, I keep getting the following error:

syntax error near unexpected token `else'

This is my code:

#!/bin/bash
DESTDIR=exip.txt
PREVIP=$(<$DESTDIR)
EXIP=$(dig +short myip.opendns.com @resolver1.opendns.com)
echo "External ip checker schript V1.0"
echo
echo
echo "Previous ip: $PREVIP"
echo
echo "Your current  external ip is $EXIP"
if [ "$PREVIP" == "$EXIP"]:then
 echo "Both IP-adresses are the same"
else
 echo "The IP addresses are diffrent"
 echo "Sending autoremote message.."
 curl "http://autoremotejoaomgcd.appspot.com/sendmessage?key=APA91bEAg6VebS03KS$
 echo "$EXIP" > "$DESTDIR"
fi

I've looked ad other topics about this error but i just can't figure it out.

2
  • use semicolon before then Commented Apr 24, 2015 at 9:54
  • And add a closing quote at the end of the URL you pass to curl. Commented Apr 24, 2015 at 9:57

1 Answer 1

4

The error is here:

if [ "$PREVIP" == "$EXIP"]:then
                         ^^

you need to add spaces around [ and ] and finally use semicolon:

if [ "$PREVIP" == "$EXIP" ]; then
                         ^^^

More generally, you can always use a tool called Shellcheck to check if your script has these common errors. It is both a command and a website, so you can paste your script in http://www.shellcheck.net/.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your help. It works now. Also thanks for the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.