Aside from the variable expansion mentioned in the question's heading, I also experience another alarming issue when reading inline data to <<EOL...  When the data contains a backtick `, it causes an error.  Both are substitution issues, but what and where is the relevant option? ...(and why is the inline read behaving differently?)Here is the script  #!/bin/bashecho '==$BASH' | \while IFS= read -r line ; do echo # output 1: $line ;doneecho '==$BASH'>junkwhile IFS= read -r line ; do echo # output 2: $line ;done <junkwhile IFS= read -r line ; do echo # output 3: $line ;done <<EOL==$BASHEOLwhile IFS= read -r line ; do echo # output 4: $line ;done <<EOL`my backtick testEOLThis is the output  # output 1: ==$BASH# output 2: ==$BASH# output 3: ==/bin/bash...: bad substitution: no closing ` in `my backtick test
Why is 'while.. read.. <
shell;bash;text processing;shell script
Shell expansion is one of the main benefits of 'here documents'. Good news is you can turn it off.Try:while IFS= read -r line ; do echo # output 3: $line ;done <<'EOL'==$BASHEOLwhile IFS= read -r line ; do echo # output 4: $line ;done <<'EOL'`my backtick testEOLFor details see:> info bash<...>3.6.6 Here Documents--------------------This type of redirection instructs the shell to read input from thecurrent source until a line containing only WORD (with no trailingblanks) is seen.  All of the lines read up to that point are then usedas the standard input for a command.   The format of here-documents is:     <<[-]WORD             HERE-DOCUMENT     DELIMITER   No parameter expansion, command substitution, arithmetic expansion,or filename expansion is performed on WORD.  If any characters in WORDare quoted, the DELIMITER is the result of quote removal on WORD, andthe 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.  In the latter case,the character sequence `\newline' is ignored, and `\' must be used toquote the characters `\', `$', and ``'.   If the redirection operator is `<<-', then all leading tabcharacters are stripped from input lines and the line containingDELIMITER.  This allows here-documents within shell scripts to beindented in a natural fashion.