syntax error: invalid arithmetic operator
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
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++)
If you are using notepad++ go to Encoding > Encode in UTF8 without BOM. Sorry I don't know anything about Mac software.
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
精彩评论