From Bash Reference Manual:
The format of here-documents is:
[n]<<[-]word here-documentdelimiter
If any part of word is quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion, the character sequence
\newline
is ignored, and\
must be used to quote the characters\
,$
, and`
.
So either escape $
(like this other answer says) or use << "EOF"
(with quotes); otherwise syntax like $variable
and $(…)
will be resolved locally.