I was asked the following question in a test on shell scripting at my university, which never gave an answer, and google is of little help.
Q: What is the line separator that should be used to end this here-document?
fff=file
xyz <<\\$fff
...
here-documentshell
I was asked the following question in a test on shell scripting at my university, which never gave an answer, and google is of little help.
Q: What is the line separator that should be used to end this here-document?
fff=file
xyz <<\\$fff
...
Best Answer
The line which ends the here document is
From the
man bash
section on Here Documents:word
does undergo quote removal, so\\$fff
is dequoted to\$fff
. But, as the manpage says, no variable expansion is done so it stays that way.The body of a here document might or might not undergo variable expansion and backslash interpretation. In this case, since
word
contains a quoted character (that is, the backslash), parameter expansion and backslash dequoting are not performed on the text of the here document.However, the input is compared with the terminating sequence before variable expansion, so it is not necessary to backslash-escape the \ nor the $ in the terminating line.