mirror of
https://codeberg.org/la-chouette/minishell.git
synced 2025-12-06 07:28:09 +01:00
notes: clarify here doc section and move it to the correct place
This commit is contained in:
parent
78298fbb1d
commit
0637a637b9
1 changed files with 62 additions and 63 deletions
125
NOTES.md
125
NOTES.md
|
|
@ -336,10 +336,9 @@ man
|
|||
|
||||
'>' refers to the standard output (fd 1, STDOUT\_FILENO)
|
||||
|
||||
TODO: check unless otherwise noted
|
||||
The word following the redirection operator, unless otherwise noted, is
|
||||
subjected to parameter expansion, filename expansion, word splitting, and
|
||||
quote removal.
|
||||
The word following the redirection operator, unless the redirection operator is
|
||||
'<<', is subjected to parameter expansion, filename expansion, word splitting,
|
||||
and quote removal.
|
||||
|
||||
If it expands to more than one word, Bash reports an error.
|
||||
|
||||
|
|
@ -357,6 +356,65 @@ bash-5.1$ echo "hello world" > $nonexist
|
|||
bash: $nonexist: ambiguous redirect
|
||||
```
|
||||
|
||||
#### Here Documents
|
||||
cf. Bash Reference Manual 3.6.6 Here Documents
|
||||
|
||||
This type of redirection instructs the shell to read input from the current
|
||||
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.
|
||||
|
||||
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, 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
|
||||
```
|
||||
|
||||
### Executing Commands
|
||||
cf. 3.7 Executing Commands
|
||||
|
||||
|
|
@ -442,65 +500,6 @@ executed command consists of the shell's initial environment, whose values may
|
|||
be modified in the shell, less any pairs removed by the 'unset' builtin, plus
|
||||
any additions via the 'export' command.
|
||||
|
||||
## Here Documents
|
||||
cf. Bash Reference Manual 3.6.6 Here Documents
|
||||
|
||||
This type of redirection instructs the shell to read input from the current
|
||||
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.
|
||||
|
||||
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, 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)
|
||||
cf. 2 Definitions
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue