0

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?

5
  • 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 Commented Jun 16, 2018 at 19:02
  • There should be closing EOF1 somewhere, probably just after "content" is stored inside myFile.append. Commented Jun 16, 2018 at 19:06
  • @ilkkachu I asked him but he didn't answer... Commented Jun 16, 2018 at 19:12
  • @jimmij but then the content behaves like a string, there's no if-then behavior, no? Commented Jun 16, 2018 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. Commented Jun 16, 2018 at 19:17

1 Answer 1

3

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.

2
  • 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. Commented Jun 16, 2018 at 19:27
  • 1
    @Kusalananda indeed, I took a bit of a shortcut there. Commented Jun 16, 2018 at 20:33

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.