15

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
}
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
slooow
  • 329
  • 1
  • 3
  • 10
  • 6
    If you like an answer, be sure to mark it as the accepted answer. It gives the responder reputation points and lets everyone else know you aren't looking for a better answer. – Yamaneko Sep 19 '12 at 22:08
  • @tripleee It's an exact duplicate: this question explicitly points out that there is no indentation, where the dupe target's problem _was_ indentation (even though you have to read through comments to see that). OTOH, it might be considered canonical because the top answer addresses both concerns. – Benjamin W. Nov 26 '17 at 20:00
  • Hmmm, so you basically agree with the duplicate marking? Or are you suggesting I change something? – tripleee Nov 27 '17 at 04:39

1 Answers1

39

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.

doubleDown
  • 8,048
  • 1
  • 32
  • 48