bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Quoted new-lines cause heredoc to consume first new-line


From: S0AndS0
Subject: Quoted new-lines cause heredoc to consume first new-line
Date: Sun, 5 Dec 2021 14:15:23 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.3.2

## How to reproduce


Copy following example into a terminal session;


```bash
gawk '{
  print $0;
}' <<'EOF'
first
second
third
EOF
```


Press `<Enter>`, then `<Arrow-Up>`
>     [user@host ~]$ gawk '{
>       print $0;
>     }' <<'EOF'first
>     second
>     third
>     EOF


Notice the `}' <<'EOF'first` bit where the first new line is consumed.


Copy following example into a terminal session;


```bash
gawk '{ print $0; }' <<'EOF'
forth
fifth
sixth
EOF
```


Press `<Enter>`, then `<Arrow-Up>`
>     [user@host ~]$ gawk '{ print $0; }' <<'EOF'
>     forth
>     fifth
>     sixth
>     EOF


Notice the `}' <<'EOF'` bit where the first new line is **not** consumed.


______


## Device stats


```bash
bash --version
```
>     5.1.8(1)-release (x86_64-pc-linux-gnu)


```bash
echo "${TERM}"
```
>     xterm-256color


```bash
uname -ro
```
>     5.13.19-2-MANJARO GNU/Linux


______


## Notes


I've tested the example commands on other devices, such as Raspberry Pi
(running their Debian based Raspian), and there are no issues with quoted new
lines causing heredoc newlines to be consumed.


> Note, on my Raspberry Pi the Bash version is `4.4.12(1)`


I submitted a question to [StackOverflow], and tests preformed by [@konsoebox] exposed the bug seems to have been introduced between versions `5.0` and `5.1`


[StackOverflow]: https://stackoverflow.com/questions/70237245/

[@konsoebox]: https://stackoverflow.com/a/70237805/2632107


---


I've also checked for differences with `shopt` options between devices, and
have not found anything, eg.

```bash
diff <(ssh rpi source '$HOME/.bashrc'; shopt -p) <(shopt -p)
```
>     #> No diff output


... So suggestions on other things to compare are certainly welcomed!


---


Near as I can tell there be some bug when writing to `history`, because;
>     [user@host ~]$ history 2 | head -n -1
>     #> 512  gawk '{
>     #>   print $0;
>     #> }' <<'EOF'first
>     #> second
>     #> third
>     #> EOF


And when a session is closed history similar to the flowing is saved;
>     [user@host ~]$ history 7 | head -n -1
>     #> 487  gawk '{
>     #> 488    print $0;
>     #> 489  }' <<'EOF'first
>     #> 490  second
>     #> 491  third
>     #> 492  EOF



reply via email to

[Prev in Thread] Current Thread [Next in Thread]