LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-14-2010, 10:57 PM   #1
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Rep: Reputation: 38
Why do I keep getting the same error in my bash script?


Hello
I keep getting this error over and over. What am I doing wrong?
Quote:
./photosync: line 7: [: missing `]'
./photosync: line 10: [: missing `]'
sending incremental file list
Here is my script
Code:
#!/bin/bash
#Synchronize photos
#sudo mount /home/server/MOM/Photos 	#destination
sudo umount /dev/sdb1
sudo mount /dev/sdb1 /mnt/sdb1		#source

if [ ! -d /mnt/sdb1/photos/keep]; then #This is line 7
	echo "Source cannot be mounted /mnt/sdb1"
		exit 0
	elif [ ! -d /home/server/MOM/Photos/keep]; then #This is line 10
			echo "Destination cannot be mounted /home/server/MOM/Photos"
		else
			rsync -avrPO  --ignore-existing /mnt/sdb1/photos/ /home/server/MOM/Photos/
			rsync -avrPO  --ignore-existing /mnt/sdb1/photo1/ /home/server/MOM/Photos/
			rsync -avrPO  --ignore-existing /mnt/sdb1/originals/ /home/server/MOM/Photos/
			echo "Photo sync is finished"
			exit 0
fi

Last edited by okos; 01-14-2010 at 10:58 PM.
 
Old 01-14-2010, 11:34 PM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Change this:
if [ ! -d /mnt/sdb1/photos/keep]
to this:
if [ ! -d "/mnt/sdb1/photos/keep"]

and change this:
]elif [ ! -d /home/server/MOM/Photos/keep]
to this:
elif [ ! -d "/home/server/MOM/Photos/keep"]

The error reported the missing opening quote (although it showed a single quote instead of double quote).
 
Old 01-14-2010, 11:54 PM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, it says
Quote:
missing `]'
In bash it's a requirement that there is at least 1 space after '[' and at least 1 space before ']' in eg an 'if' statement.
No quotes reqd.
I recommend double [[ ]] anyway: http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS
Quote:
Using the [[ ... ]] test construct, rather than [ ... ] can prevent many logic errors in scripts. For example, the &&, ||, <, and > operators work within a [[ ]] test, despite giving an error within a [ ] construct.
 
Old 01-15-2010, 10:11 PM   #4
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
Quote:
Originally Posted by bigrigdriver View Post
Change this:
if [ ! -d /mnt/sdb1/photos/keep]
to this:
if [ ! -d "/mnt/sdb1/photos/keep"]

and change this:
]elif [ ! -d /home/server/MOM/Photos/keep]
to this:
elif [ ! -d "/home/server/MOM/Photos/keep"]

The error reported the missing opening quote (although it showed a single quote instead of double quote).
I tried the double quote same problem.
Ive messed with it for a while and am still scratching my head.

[edit]
Chris thanks for the post. I missed it before replying. Ill give it a try.

Last edited by okos; 01-15-2010 at 10:14 PM.
 
Old 01-15-2010, 10:19 PM   #5
Elv13
Member
 
Registered: Apr 2006
Location: Montreal,Quebec
Distribution: Gentoo
Posts: 825

Rep: Reputation: 129Reputation: 129
you need to add a space before "]"

if [ "test" == "test" ]; then
echo test
fi
 
Old 01-17-2010, 07:17 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
@Elv13: see my post #3
 
Old 01-25-2010, 11:30 PM   #7
okos
Member
 
Registered: May 2007
Location: California
Distribution: Slackware/Ubuntu
Posts: 609

Original Poster
Rep: Reputation: 38
BTW the space was what I needed
Thanks
 
  


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
Bash Script Error nathacof Programming 2 01-20-2009 06:37 PM
bash script read error and awk ouptut error whited Programming 4 10-16-2007 07:05 PM
bash script error noir911 Programming 4 09-27-2006 07:52 AM
bash script error noir911 Programming 5 09-12-2006 06:42 AM
error when tying to run python script(bash error?) shanenin Programming 5 01-10-2006 10:01 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 05:51 AM.

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