以下代码段给出错误:14:语法错误:文件意外结束
#!/bin/bash
func_some()
{
cd some_directory
lftp -u user,'password' sftp://192.168.xx.xx <<EOF
cd some_directory
mget ADMS_report_*${2}${3}${4}*.txt
}
#------------------------------ Main function ------------------------------
func_some 2017 08 08 2017 08 07
但是如果我删除 <<EOF
然后脚本只登录但不执行后续命令并无限期地保持登录状态。
解决这个问题的方法是什么?我犯了什么错误?
最佳答案
<<EOF
表示heredoc的开始
A here document is a special-purpose code block. It uses a form of I/O redirection to feed a command list to an interactive program or a command, such as ftp, cat, or the ex text editor.
然后你应该关闭你的 heredoc 代码块,像这样:
func_some()
{
cd some_directory
lftp -u user,'password' sftp://192.168.xx.xx <<EOF
cd some_directory
mget ADMS_report_*${2}${3}${4}*.txt
EOF
}
否则它将继续搜索限制字符串 ( EOF
),
并在到达文件末尾时因语法错误而失败。
注意限制字符串,必须放在行首, 前面没有空格。
关于linux - shell脚本中的EOF问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45561437/