Bash: warning: here-document at line delimited by end-of-file (wanted `EOF') [duplicate]

好久不见. 提交于 2019-11-27 06:58:20

问题


This question already has an answer here:

  • here-document gives 'unexpected end of file' error 5 answers

The following function in bash comes up with the error mentioned in the title. The error usually appears when the final EOF is not at the beginning of the line.

EOF is at the beginning so I can't see what is wrong. Further up in the script (not shown) there are other here-docs and they work.

add_testuser()
{
    kadmin -p admin -q addprinc test
    cat <<EOF > ~/test.ldif
dn: cn=test,ou=groups,dc=${ARRAY[1]},dc=${ARRAY[2]}
cn: test
gidNumber: 20001
objectClass: top
objectClass: posixGroup

dn: uid=test,ou=people,dc=${ARRAY[1]},dc=${ARRAY[2]}
uid: test
uidNumber: 20001
gidNumber: 20001
cn: First_name
sn: Last_name
objectClass: top
objectClass: person
objectClass: posixAccount
objectClass: shadowAccount
loginShell: /bin/bash
homeDirectory: /home/test
userPassword: {CRYPT}*
EOF 

    ldapadd -Qf ~/test.ldif
    kdestroy; kinit test
    klist
    ldapwhoami
}

回答1:


You have a space after the final EOF hence it was unable to terminate the heredoc.

p/s: Noticed this while copy-pasting your code.



来源:https://stackoverflow.com/questions/12503581/bash-warning-here-document-at-line-delimited-by-end-of-file-wanted-eof

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!