Shell exits after process substitution when using DEBUG trap with extdebug

2020-08-03 Thread Jonathan Rascher
$ bash --version
GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)

$ uname -a
Linux penguin 5.4.40-04224-g891a6cce2d44 #1 SMP PREEMPT Tue Jun 23 20:21:29
PDT 2020 x86_64 GNU/Linux

(This is a Pixelbook running the default Crostini Linux VM under Chrome
OS 84.0.4147.110. I can reproduce the issue on regular Debian too, though.)

To reproduce, run the following commands:

shopt -s extdebug
trap : DEBUG
: < <(:)

Now, type any character (e.g., 'a'). At this point, you'll see bash print
`exit`, and the shell does indeed exit. Additionally, assuming you ran bash
inside another shell, you'll see the 'a' character is echoed.

It's a hard to describe clearly, but the result looks like this
(`bcat@penguin:pts/0` is the prompt from my outer shell):

bcat@penguin:pts/0 J:0 ~
$ bash --norc
bash-5.0$ shopt -s extdebug
bash-5.0$ trap : DEBUG
bash-5.0$ : < <(:)
bash-5.0$ [I TYPED 'a' HERE]exit
bcat@penguin:pts/0 J:0 ~
$ a

The inner shell with the DEBUG trap acts as if it received an EOF on stdin,
and exits accordingly, but the 'a' character I typed into my terminal is
indeed still there, and it's echoed by the outer shell after the inner
shell (wrongly) exits. I wonder if stdin of the inner shell is getting
screwed up by the extdebug DEBUG trap somehow.

Cheers,
Jon


Re: Shell exits after process substitution when using DEBUG trap with extdebug

2020-08-04 Thread Jonathan Rascher
On Tue, Aug 4, 2020 at 9:20 AM Chet Ramey  wrote:

> On 8/3/20 9:44 PM, Jonathan Rascher wrote:
> > $ bash --version
> > GNU bash, version 5.0.3(1)-release (x86_64-pc-linux-gnu)
> >
> > $ uname -a
> > Linux penguin 5.4.40-04224-g891a6cce2d44 #1 SMP PREEMPT Tue Jun 23
> 20:21:29
> > PDT 2020 x86_64 GNU/Linux
> >
> > (This is a Pixelbook running the default Crostini Linux VM under Chrome
> > OS 84.0.4147.110. I can reproduce the issue on regular Debian too,
> though.)
> >
> > To reproduce, run the following commands:
> >
> > shopt -s extdebug
> > trap : DEBUG
> > : < <(:)
>
> Thanks for the report. I can't reproduce this with macOS, but I can with
> RHEL 7. I'll take a look.
>

Thanks!

The EOF hunch made me decide to see what happened with ignoreeof set. Sure
enough, instead of exiting when I type the first character after the
command with the process substitution, bash just prints `Use "exit" to
leave the shell.` And then the character I actually typed is still echoed
to the console, and I can keep using the shell. (It doesn't exit if
ignoreeof is set.)

Cheers,
Jon