LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Why do I keep getting the same error in my bash script? (https://www.linuxquestions.org/questions/linux-software-2/why-do-i-keep-getting-the-same-error-in-my-bash-script-782304/)

okos 01-14-2010 10:57 PM

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


bigrigdriver 01-14-2010 11:34 PM

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).

chrism01 01-14-2010 11:54 PM

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.

okos 01-15-2010 10:11 PM

Quote:

Originally Posted by bigrigdriver (Post 3827096)
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. :banghead:

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

Elv13 01-15-2010 10:19 PM

you need to add a space before "]"

if [ "test" == "test" ]; then
echo test
fi

chrism01 01-17-2010 07:17 PM

@Elv13: see my post #3

okos 01-25-2010 11:30 PM

BTW the space was what I needed
Thanks


All times are GMT -5. The time now is 05:36 PM.