LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-10-2009, 09:14 PM   #1
gods_design
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Rep: Reputation: 0
Shell Scripting Problem: command not found


I am writing a small script to check my public ip against a php page I host and then if the ip has changed it will trigger an update in some files. When I run the script it gives me the error "command not found"

Here is the code:
Code:
#!/usr/local/bin/bash

OLD_IP=`cat /tmp/currentip`
CURRENT_IP=`curl -s http://toomanymiles.net/publicip.php`

if ["$CURRENT_IP" == "$OLD_IP"]
then 
        echo "IP Current"
else
        echo $CURRENT_IP > /tmp/currentip
        echo "IP Updated!"
fi
The output I get is:
Code:
-bash-3.2$ ./checkip.sh 
./checkip.sh: line 6: [77.29.41.58: command not found
IP Updated!
I know it is probably something simple but I can't figure out what I am doing wrong.
 
Old 02-10-2009, 09:50 PM   #2
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Change
Code:
if ["$CURRENT_IP" == "$OLD_IP"]
to
Code:
if [ "$CURRENT_IP" == "$OLD_IP" ]
Believe it or not, this works because
Code:
[
is actually a command, and it is equivalent to
Code:
test
If you jam the IP address right up against the [, you'll get an entirely different (and nonexistent, as you found out) command.

Hope this helps.
 
Old 02-10-2009, 09:53 PM   #3
alan_ri
Senior Member
 
Registered: Dec 2007
Location: Croatia
Distribution: Debian GNU/Linux
Posts: 1,733
Blog Entries: 5

Rep: Reputation: 127Reputation: 127
Ignore this post.

Last edited by alan_ri; 02-11-2009 at 04:40 PM. Reason: correction
 
Old 02-10-2009, 11:58 PM   #4
gods_design
LQ Newbie
 
Registered: Feb 2009
Posts: 2

Original Poster
Rep: Reputation: 0
Just when I thought i had tried everything. Thank you that worked great.

Quote:
Originally Posted by wje_lq View Post
Change
Code:
if ["$CURRENT_IP" == "$OLD_IP"]
to
Code:
if [ "$CURRENT_IP" == "$OLD_IP" ]
Believe it or not, this works because
Code:
[
is actually a command, and it is equivalent to
Code:
test
If you jam the IP address right up against the [, you'll get an entirely different (and nonexistent, as you found out) command.

Hope this helps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
goto/label command for scripting in bash shell terry.trent Linux - Software 3 07-09-2010 10:15 AM
shell scripting/ bash/ a command with 3 parameters mayaabboud Programming 4 01-05-2008 10:22 AM
shell scripting/ the fc -l command ! mayaabboud Linux - Newbie 12 01-03-2008 06:38 PM
shell scripting problem, sed command kamkos Linux - General 5 03-31-2007 09:39 PM
Shell Scripting - use the output of a command as an argument for another timgiffney Programming 6 04-17-2006 11:13 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:11 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration