greater-than + number sign = newlines in history

2020-05-03 Thread Tobias Wendorff
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS: -g -O2
-fdebug-prefix-map=/build/bash-2bxm7h/bash-5.0=.
-fstack-protector-strong -Wformat -Werror=format-security -Wall
-Wno-parentheses$
uname output: Linux inwis-wohnlagen 5.4.0-0.bpo.4-amd64 #1 SMP Debian
5.4.19-1~bpo10+1 (2020-03-09) x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 5.0
Patch Level: 3
Release Status: release

Description:
When creating a here document containing the greater-than sign followed
by number sign, newlines get added to Bash history:
```
$ history
  1  cat << 'EOF' > /dev/null
<#a

<#b

EOF
```

Repeat-By:
```
$ cat << 'EOF' > /dev/null
<#a
<#b
EOF
```



Re: greater-than + number sign = newlines in history

2020-05-03 Thread Tobias Wendorff
Am 03.05.2020 um 14:50 schrieb Robert Elz:
> The example given showed a less than, rather than greater than,
> but that turns out to be irrelevant, it is the '#' that is triggering
> this.

Whoops, sorry.

> Any line in a here doc that contains a # gets an extra \n appended
> to it in history (doesn't matter if the end marker is quoted or not,
> doesn't seem to matter what else is on the line, if anything, with the '#'.
> (Obviousl;y I haven't tested every possibility).

Is this behavior planned or unplanned? The problem doesn't seem to
appear on Bash 4 (Debian Jessie, Cygwin on Windows).

> If the history entry is used (up-arrow, return) to replay the command, a
> new entry will be made with extra \n chars in it (the repeated command
> is not seen as a duplicate - I have the var set to have dup commands
> saved just once).

It's also stored in Bash's history file.

On IRC, an user gave me the hint to set `shopt -s lithist`, which seems
to work. The documentation of `lithist` is very ambiguous, so I don't
know the downside of this option.