Syntax error: end of file unexpected (expecting fi)

Syntax error: end of file unexpected (expecting fi)

我正在写一个备份脚本。 我认为我的语法是正确的,但它仍然给我一个错误。

这是我的脚本:

if [ ! -f $LIST ]; then
    /usr/bin/tar -g $FULLLIST -zpcf $FULL $TGT
    cp $FULLLIST $DIFFLIST
    expect << EOF
    spawn /usr/bin/scp $FULL $HOST:$DST
    expect "password:"
    send "blahblah\r"
    expect eof
    EOF
    rm $FULL
elif [ $DAY == 01 ]; then
    *same as above*
elif [ $DAYOFWEEK == 0 ]; then
    *same as above*
else
    *same as above*
fi

错误是

Syntax error: end of file unexpected (expecting "fi")

当我输入“./webbackup.sh”时

您错误地关闭了此处文档。当你写的时候:

expect <<EOF

该行必须完全 EOF前后没有空格。正是 EOF。你想要:

    expect << EOF
    spawn ...
^^^^ - these spaces are "preserved"
EOF
   ^ also no spaces after!

您可以使用 -<delimiter>,然后它将忽略前导制表符。 不是空格.

    expect <<-EOF
    spawn /usr/bin/scp $FULL $HOST:$DST
    ...
    EOF
^^^^ - this is a tab character

在 shell 中研究 此处文档