-1

In this post, Stephen's answer displays this code:

cat <<-"EOF1" >> myPath/myFile.append
if ! grep -F -q -f myPath/myFile{.append,}; then
    cat myPath/myFile.append >> myPath/myFile
fi

How come there is no delimiter to the heredocument?

  • 1
    seeing that it was an answer to a question of yours, I think you could have just asked this from him directly, with a comment on the answer – ilkkachu Jun 16 '18 at 19:02
  • There should be closing EOF1 somewhere, probably just after "content" is stored inside myFile.append. – jimmij Jun 16 '18 at 19:06
  • @ilkkachu I asked him but he didn't answer... – user9303970 Jun 16 '18 at 19:12
  • @jimmij but then the content behaves like a string, there's no if-then behavior, no? – user9303970 Jun 16 '18 at 19:12
  • @user9303970, hm, I didn't see that comment. Anyway, I edited said answer to add the parts that seemed to be missing. – ilkkachu Jun 16 '18 at 19:17
2

All shells I tested read a here-document just fine even without the terminator, the here-doc will just end at end-of-file then. Bash gives a warning about this, but busybox/dash/ksh and zsh just handle it silently.

E.g.

$ cat heredoctest.sh
#!/bin/bash
cat -n <<EOF
foo
bar
$ bash heredoctest.sh
heredoctest.sh: line 4: warning: here-document at line 2 delimited by end-of-file (wanted `EOF')
     1  foo
     2  bar

But the particular sample of code you present seems like an error. As it's written, it would just append the if-statement to myPath/myFile.append, which doesn't seem too useful. It looks like the here-doc contents and the terminator are just missing from between the cat and the if.

  • I saw Stephen's answer and I assumed it was an omission of the actual here-document (and end marker). I did not comment on it though. – Kusalananda Jun 16 '18 at 19:27
  • 1
    @Kusalananda indeed, I took a bit of a shortcut there. – Stephen Kitt Jun 16 '18 at 20:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.