From 806e98ac971696a017b7e16830f7dad91c33e1bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kha=C3=AFs=20COLIN?= Date: Tue, 11 Feb 2025 13:22:47 +0100 Subject: [PATCH] notes: clarified note about parameter expansion in here doc Still need to see if we have to implement that.. --- NOTES.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 49 insertions(+), 8 deletions(-) diff --git a/NOTES.md b/NOTES.md index f75c725..22e5d3a 100644 --- a/NOTES.md +++ b/NOTES.md @@ -459,15 +459,56 @@ source until a line containing only word (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command. -TODO: The following paragraph may not apply fully to our project, check it again! - No parameter and variable expansion, command substitution, arithmetic expansion, -or filename expansion is performed on word. If any part of word is 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 ‘`’. +or filename expansion is performed on word. + +If any part of word is 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, and the +character sequence \\newline is ignored. + +This is the correct behaviour for quoting and parameter expansion: +```shell +bash-5.2$ cat << EOF +> hello +> $$ +> EOF +hello +1491742 +bash-5.2$ cat << "EOF" +> hello +> $$ +> EOF +hello +$$ +bash-5.2$ cat << 'E'OF +> hello +> $$ +> EOF +hello +$$ +bash-5.2$ cat << $USER +> hello +> khais +> $USER +hello +khais +bash-5.2$ echo $USER +khais +bash-5.2$ cat << "$USER" +> $USER +``` + +TODO: do we need to ignore \\newline? subject says \\ is not required.. + +If we have to implement it, this is the correct behaviour: +```shell +bash-5.2$ cat << EOF +> hello \ +world +> EOF +hello world +``` ## Definitions cf. [Bash Reference Manual](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Definitions)