【问题标题】:Error while FTPing filesFTP传输文件时出错
【发布时间】:2012-11-19 14:49:27
【问题描述】:

执行脚本时出现以下错误。不知道我哪里弄错了。

错误信息:

./ftp_send_script.sh: line 40: syntax error: unexpected end of file

这是脚本

#!/usr/bin/bash

#Define Variables
#------------------------------------------------------------------------------

HOST=qftpserver
USER=ftpuser
PASS=password

#------------------------------------------------------------------------------

#FTP files
#------------------------------------------------------------------------------
for FILE in `ls *.txt`
do
        ftp -n -p << EOT
        open $HOST
        user $USER $PASS
        prompt n
        type binary
        mput ${FILE}
        quit
        EOT
echo ${FILE}
done
#------------------------------------------------------------------------------

【问题讨论】:

    标签: bash unix ftp


    【解决方案1】:

    heredoc 中的终止符必须在一行的开头,而不是缩进:

    for FILE in `ls *.txt`
            ...
            mput ${FILE}
            quit
            EOT
    

    应该是

    for FILE in `ls *.txt`
         ...
         mput ${FILE}
         quit
    EOT    <---start in column 0, not indented.
    

    由于你的缩进,heredoc 实际上并没有终止,shell 解析器只是在脚本的末尾运行,因此你的 unexpected end of file

    【讨论】:

    • 成功了。我不知道缩进会有所作为。谢谢。
    • heredoc 终止符必须单独在一行上,并且该行上的任何文本都被视为该终止符字符串的一部分。所以你实际上有[tab][tab]EOT(或[空格]。无论你使用什么),shell 正在寻找EOT。因为它从来没有看到一个裸露的EOT,所以heredoc 从来没有关闭过,你跑出了脚本的底部。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 1970-01-01
    • 2010-11-18
    • 1970-01-01
    相关资源
    最近更新 更多