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 ... The line which ends the here document is
\$fff From the man bash section on Here Documents:
The format of here-documents is:
<<[-]word here-document delimiter No parameter and variable expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are 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 `.
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.
here document, not the terminator. The terminator - called the delimiter in man bash - is, as per your quote from man bash, "the delimiter is the result of quote removal on word" The terminator is
\$fff I'm going to assume that that's what @rici meant to say. As his penultimate paragraph says,
worddoes undergo quote removal, so\\$fffis dequoted to\$fff. But, as the man page says, no variable expansion is done so it stays that way.
<<EOFisEOF, then the answer to<<foomust befoo) without really having the ability to answer questions or knowing the underlying theory. … C’d<<footo<<baris trivial) and that does challenge their understanding of the underlying rules and mechanisms. That said, I agree with you; for a person to be able to answer that in a closed-book exam, he would have had to memorize every word ofbash(1). I personally, would have guessed that<<$fffwould have a terminator offile. … (Cont’d)printfconversion type (i.e., the letter after the%) for printing floating point numbers?”. I disapprove of questions like … (Cont’d)printfconversion specification to print a floating-point number with five character positions to the left of the decimal point (including-sign if appropriate, and leading spaces if necessary) and two digits to the right of the decimal point?” (unless it’s an open-book test). I believe that there’s no benefit to memorizing theprintfspecs to that level of detail. The first couple of times you need to print a floating-point number, you’ll check the man page. If it’s something that you do often enough, you’ll learn it through repetition.