On 11/17/21 1:45 PM, João Almeida Santos wrote: > No, it’s on the email...Anyway, here’s the text! > > bash-5.1$ echo $PATH > /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/:/usr/local/bin/:/usr/local/bin/ > > bash-5.1$ cat << $PATH >> /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/:/usr/local/bin/:/usr/local/bin/ >> it should have terminated with the upper delimiter! but, bash does not seem >> to expand PATH. >> $PATH > /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin/:/usr/local/bin/:/usr/local/bin/ > it should have terminated with the upper delimiter! but, bash does not seem > to expand PATH.
The here document delimiter does not undergo any expansions except quote removal, so the delimiter is the literal string `$PATH'. The lines of the here-document undergo a different set of expansions, which happen after the check for the delimiter is performed, which means that you need to have a line that consists solely of `$PATH' to terminate the here-document (as you discovered). I cannot see how you're going to be able to do anything useful with this construct; it just seems too clever by (more than) half. This is all in the bash documentation. > ok, but now addressing the actual question. If I use unclosed quotes on > heredoc, I can't use > the given delimiter to end the heredoc, I end up having to use an EOF. > Example: > > bash-5.1$ > bash-5.1$ cat « ola" >> I, >> ola"" >> ola" >> ola The delimiter is not what you think it is. The delimiter for a here- document is a shell word (which can include quoted substrings), and after it undergoes the appropriate quote removal, your delimiter is "ola\nI,\nola\nola" (using C string notation). Now, you're never going to be able to match this; it contains a newline. When the shell constructs the here-document body, it reads individual lines from the input source and, after removing the trailing newline, tries to match them against the delimiter (and backslash doesn't work to quote the newline). This will obviously never match a delimiter containing a newline. Some shells (e.g., yash) choose to make this a syntax error. Bash does not. > In the above example, I don't unterstand how to provide the wanted delimiter! You simply cannot, not the way you specify it. If you really want to have the double quote as part of the here-document delimiter, write it as cat << ola\" I can't imagine this being useful, either. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/