2

Is there any difference between:

cat <<END
    {"@json-stdio":true,"value":"$pack"}
END

and

cat <<EOF
    {"@json-stdio":true,"value":"$pack"}
EOF

?

  • there's no difference between END and EOF, but there's a big difference between <<END and <<'END' or <<"END"; only the first will perform (variable & other) expansions in the here-document. – mosvy Dec 22 '18 at 5:24
  • Yes spelling, and nothing else. Choose a word that is not in the document. – ctrl-alt-delor Dec 22 '18 at 12:10
4

No; the word that delimits the here-document can be (almost) anything.

3.6.6 Here Documents

This type of redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks) is seen.

... where word is:

A sequence of characters treated as a unit by the shell. Words may not include unquoted metacharacters

... and metacharacters are:

A character that, when unquoted, separates words. A metacharacter is a space, tab, newline, or one of the following characters: ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ‘<’, or ‘>’.

  • notice that you can include any of those characters in the here-doc delimiter (including newlines with dash and ksh93), provided that you're quoting it. Example: printf 'cat <<" a () <> & "\nA\nB\n a () <> & \necho done\n' | bash and printf 'cat <<" a \n b "\nA\nB\n a \n b \necho done\n' | dash – mosvy Dec 22 '18 at 6:49

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.