简体   繁体   English

语法错误:意外的文件结束

[英]syntax error: unexpected end of file

I am getting this error when I run my Bash script: 我运行Bash脚本时收到此错误:

syntax error: unexpected end of file 语法错误:意外的文件结束

Cant really find where the error is, been looking for hours and still get this error. 无法找到错误的位置,一直在寻找数小时但仍然会收到此错误。

Here is the script hope some one cant point me in the right direction: 这是脚本希望有人不能指出我正确的方向:

#!/bin/bash 


BACKUPDIR=~/backup
SCRIPTDIR=~/respaldar
BACKUPFILE=/respaldo.$(date +%F).bz2
BACKUPHOST=199.21.112.70
COUNT=$(ls $BACKUPDIR | wc -l)
TRESHOLD=7




if [[ ! -e $BACKUPDIR ]]
then
     echo "Creating Backup Directory because it doesn\'t exist !"
    mkdir ~/backup
    COUNT=0
#    exit 0
else
   COUNT=$(ls $BACKUPDIR | wc -l)
fi




if [[ $COUNT -le $THRESHOLD ]]
then
      tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR 
      if [[ $? -ne 0 ]]; then echo "Problems Creating Backup File;"  fi
      scp $BACKUPDIR/$BACKUPFILE $BACKUPHOST:
      if [[ $? -ne 0 ]]; then echo "Problems Copying Backup File to Backup Host;" fi
fi







#END

Appreciate the help. 感谢帮助。

I copyed the whole stuff to and it spotted the same thing as fedorqui : 我将整个东西fedorqui ,它发现了与fedorqui相同的东西:

if [[ $? -ne 0 ]]; then echo "Problems Creating Backup File;"  fi
...
if [[ $? -ne 0 ]]; then echo "Problems Copying Backup File to Backup Host;" fi

The ; ; is before " and should be after. 是在"之前,应该在之后。

I would suggest to use a shorter solution in both cases: 我建议在两种情况下使用更短的解决方案:

[ $? -ne 0 ] && echo "Problems Creating Backup File">&2 && exit 1

This will exit if fails. 如果失败,这将退出。 Or even the more talkative version: 甚至更健谈的版本:

tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR || \
    { echo "Problems Creating Backup File">&2;exit 1;}

Or if You want to see an error message only if the whole process fails: 或者,如果您只想在整个过程失败时才看到错误消息:

tar -cjvf $BACKUPDIR/$BACKUPFILE $SCRIPTDIR && \
    scp $BACKUPDIR/$BACKUPFILE $BACKUPHOST: || \
    { echo "Backup failed">&2;exit 1;}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM