未检测到结束 EOF

Nie*_*els 0 bash eof psql

我有以下功能;

function getdetails {
    if ! "${PSQL_PATH}" -d "$DB" -U "$DB_USER" -h localhost -p "$DB_PORT" -t -c  | while read -a Record ; do
        taskid="${Record[0]}"
        clientname="${Record[1]}"
        backup_pass="${Record[2]}"
        backup_dir="${Record[3]}"
      done; then
            echo "Could not fech next task metadata from database"
            exit 1
      fi <<EOF
        WITH firsttask AS (SELECT taskid from tasks 
                            WHERE status = 'PENDING'
                            ORDER BY date_started ASC
                            LIMIT 1)
        SELECT taskid, username, storage_password AS backup_password, location AS backup_dir 
        FROM firsttask 
        INNER JOIN users USING (userid)
        INNER JOIN storage USING (userid)
        WHERE (username = '$1');
EOF 
}
Run Code Online (Sandbox Code Playgroud)

由于某种原因,bash 没有检测到最后一个EOF并报告: ./processor.sh: line 138: warning: here-document at line 41 delimited by end-of-file (wanted `EOF') ./processor.sh: line 139: syntax error: unexpected end of file

有什么想法为什么EOF没有被采纳吗?谢谢你!

gei*_*rha 5

它失败是因为结束EOF词有尾随空格。它必须单独占一行,没有前导或尾随空格。

使用语法时有一个例外<<-,在这种情况下,结束词前面可能有一个或多个制表符(但绝不能有空格)。