help-bash
[Top][All Lists]
Advanced

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

Re: exec 0<.... question


From: Greg Wooledge
Subject: Re: exec 0<.... question
Date: Tue, 29 Oct 2024 22:35:15 -0400

On Wed, Oct 30, 2024 at 03:22:47 +0100, #!microsuxx wrote:
> if i exec 0 like from a fifo , exec without cmd
> can i type then into the bash cmdline and it appears rather into the fifo
> or , does it apply just on next cmd

File descriptor 0 is standard input.  If you do "exec 0<somefifo" you
will close stdin (which was previously reading from your terminal) and
instead try to read from your FIFO.

The exec call will block until the FIFO has *also* been opened for writing
by some other process.

Once the exec call finishes, the FIFO has been opened twice by two
different processes, and your shell is ready to read input from the
FIFO.

It will not read input from your terminal any longer.

If you want to play around with this, open two terminal windows, and then:

 1. In window 1, create a FIFO (e.g. mkfifo p).
 2. In window 1, do "exec 0<p".  This will hang.
 3. In window 2, do "exec 1>p".  This should un-hang window 1.
 4. In window 2, type a simple command, like "echo date".
    The *output* of your command will be written to the FIFO, and read
    as input by the shell in window 1.
 5. In window 1, type whatever you want, and observe that it is ignored.
 6. In window 2, exit from the shell.  Window 1 will also be closed.
 7. Don't forget to clean up your FIFO.



reply via email to

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