help-bash
[Top][All Lists]
Advanced

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

Re: Process substitution documentation request


From: Chet Ramey
Subject: Re: Process substitution documentation request
Date: Mon, 15 Jun 2026 10:39:27 -0400
User-agent: Mozilla Thunderbird

On 6/12/26 11:58 PM, Borden via wrote:
I'm trying to figure out the mechanics of process substitution from 
https://www.gnu.org/software/bash/manual/html_node/Process-Substitution.html 
and the rest of the Internet.

Process substitution creates pipes for reading (<(cmd)) or writing
(>(cmd)) between the shell, or a process it creates to execute a
command, and `cmd'. These are essentially the same as anonymous pipes
created by shell pipelines (command1 | command2), but are exposed to the
calling shell using  pathnames. These pathnames are of the form /dev/fd/N,
where N is the pipe file descriptor, or as a named pipe the shell creates.

That pathname is the result of the process substitution word expansion.

If you use <(cmd), for instance, the shell will create a pipe and
use its write end as cmd's standard output. The pathname it exposes
as the result of the expansion will be the read end of the pipe. Opening
that file will allow whichever process opens it to read the output of
`cmd'.

If you have a command line that looks like this before expansion:

executable <(cmd)

Then `executable' sees, for instance, /dev/fd/62 as its argument. If
`executable' opens /dev/fd/62 (the pathname it sees as one of its
arguments) for reading, it will be able to read the output of `cmd'.

The documentation implies that process substitution works much like piping in 
and out of temporary files.

Nothing of the sort. Pipes and files are separate objects.

I'm struggling to figure out how asynchronous IO works,

Do you need to understand it to understand how pipes work?

There are lots of nuances of how a file descriptor is opened, filled, emptied and closed 
that I'm discovering from error messages of "broken pipes". The documentation 
doesn't seem to help.

Pipes are a basic Unix concept, so maybe an intro to Unix/Linux guide would
help here?


I understand C++ and Python IO where one opens a file, reads or writes to it, 
then commits the changes to disk. I can also do the same with byte streams in 
memory. That paradigm seems to be working against me with process substitution.

Pipes are essentially I/O channels between processes.

The bash manual doesn't need a lengthy explanation on asynchronous IO. It would 
be sufficient to explain the differences named pipes have from stream 
redirectors, generally explain how named pipes can be read and written, and 
what users should search for in their foundational research.

The bash manual isn't the place for an introduction to concepts like pipes;
it assumes you know what they are and tells you how you can use them. That
belongs in an introductory book, of which there are hundreds.

Chet

--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/

Attachment: OpenPGP_signature.asc
Description: OpenPGP digital signature


reply via email to

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