Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug: reading from tty inside process substitution



On Sun, Nov 12, 2023 at 7:59 AM Mark J. Reed <markjreed@xxxxxxxxx> wrote:
>
> The below code hangs after reading the line from the terminal:
>
>     read foo < <(read bar </dev/tty; echo $bar)

I believe it actually hangs before reading the line from the terminal,
or more precisely at the point of trying to read the line.  "read bar"
is being stopped by a SIGTTIN signal because it is not in a process
group that "owns" the TTY.

This has to do with the way zsh backgrounds the process substitution.
It actually works fine in a script or even in a subshell (which
explains why it works in command substitution):

% zsh -fc 'read foo < <(read bar </dev/tty; echo $bar); echo $foo'
the line
the line
%  ( read foo < <(read bar </dev/tty; echo $bar); echo $foo )
subshell
subshell
%

In an interactive shell with job control, though, the process
management is different.

% unsetopt monitor
% read foo < <(read bar </dev/tty; echo $bar); echo $foo
no job control
no job control
%

I doubt there's any easy way to change this without breaking something else.




Messages sorted by: Reverse Date, Date, Thread, Author