notes: clarified note about parameter expansion in here doc

Still need to see if we have to implement that..
This commit is contained in:
Khaïs COLIN 2025-02-11 13:22:47 +01:00
parent e6e108a98d
commit 806e98ac97
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -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 of the lines read up to that point are then used as the standard input for a
command. command.
TODO: The following paragraph may not apply fully to our project, check it again!
No parameter and variable expansion, command substitution, arithmetic expansion, No parameter and variable expansion, command substitution, arithmetic expansion,
or filename expansion is performed on word. If any part of word is quoted, the or filename expansion is performed on word.
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 If any part of word is quoted, the delimiter is the result of quote removal on
here-document are subjected to parameter expansion, command substitution, and word, and the lines in the here-document are not expanded. If word is unquoted,
arithmetic expansion, the character sequence \newline is ignored, and \ must all lines of the here-document are subjected to parameter expansion, and the
be used to quote the characters \, $, and `. 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 ## Definitions
cf. [Bash Reference Manual](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Definitions) cf. [Bash Reference Manual](https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Definitions)