0

running the below script I receive :

line 8: ((: i = 0 : syntax error: invalid arithmetic operator (error token is " ")

Any idea what is wrong? Can it be the I edit with text editor on an iMac? something to do maybe with a CR?

domains=( yourdomain.com yourdomain2.com )
sqldbs=( yourdb1 yourdb2 )
opath=$HOME/backup/
mysqlhost=mysqlhostname
username=mysqlusername
password=mysqlpassword
suffix=$(date +%m-%d-%Y)
for (( i = 0 ; i < ${#domains[@]} ; i++ ))
do
    cpath=$opath${domains[$i]}
    if [ -d $cpath ]
    then
        filler="just some action to prevent syntax error"
    else
        echo Creating $cpath
        mkdir -p $cpath
    fi
    mysqldump -c -h $mysqlhost --user $username --password=$password ${sqldbs[$i]} > ${cpath}/${sqldbs[$i]}_$suffix.sql
done

3 Answers 3

1

The error code is telling you what the problem is: you have an extra space. Line 8 should be:

for (i=0; i<${#domains[@]}; i++)
Sign up to request clarification or add additional context in comments.

3 Comments

I changes line 8 as adviced and now i received: line 8: syntax error near unexpected token (' line 8: for (i=0; i<${#domains[@]}; i++)'
@Jailbreak, are you using bash or sh?
the script is mentioned here: wiki.dreamhost.com/Mysqldump SHELL=/bin/bash
0

If you are using notepad++ go to Encoding > Encode in UTF8 without BOM. Sorry I don't know anything about Mac software.

1 Comment

Not possible. BOM is the first thing in the file, OP's getting and error on line 8.
0

I copied and paste again line 8 (as it was in script) and worked fine. It appears that parsing errors were due an extra character in line 8

Comments

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.