Bash:警告:此处文档位于由文件结尾分隔的行(需要“EOF”)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12503581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Bash: warning: here-document at line delimited by end-of-file (wanted `EOF')
提问by slooow
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.
bash 中的以下函数出现了标题中提到的错误。当finalEOF
不在行的开头时,通常会出现错误。
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.
EOF
是在开头,所以我看不出有什么问题。在脚本(未显示)的更深处,还有其他 here-docs 并且它们有效。
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
}
回答by doubleDown
You have a space after the final EOF
hence it was unable to terminate the heredoc.
您在 final 之后有一个空格,EOF
因此无法终止 heredoc。
p/s: Noticed this while copy-pasting your code.
p/s:在复制粘贴代码时注意到了这一点。