LinuxQuestions.org
Help answer threads with 0 replies.
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, 11: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 11:58 PM.
 
Old 01-15-2010, 12:34 AM   #2
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,903

Rep: Reputation: 353Reputation: 353Reputation: 353Reputation: 353
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-15-2010, 12:54 AM   #3
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,418

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
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, 11: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 11:14 PM.
 
Old 01-15-2010, 11: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, 08:17 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,418

Rep: Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398Reputation: 2398
@Elv13: see my post #3
 
Old 01-26-2010, 12:30 AM   #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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

All times are GMT -5. The time now is 01:23 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration