Questions tagged [process-substitution]

Process substitution a form of inter-process communication that allows the input or output of a command to appear as a file (such as: `<(cmd)` or `>(cmd)`).

Filter by
Sorted by
Tagged with
80
votes
5answers
25k views

Process substitution and pipe

I was wondering how to understand the following: Piping the stdout of a command into the stdin of another is a powerful technique. But, what if you need to pipe the stdout of multiple commands? ...
26
votes
1answer
4k views

Why does BASH process substitution not work with some commands?

On occasion process substitution will not work as expected. Here is an example: Input: gcc <(echo 'int main(){return 0;}') Output: /dev/fd/63: file not recognized: Illegal seek collect2: error: ...
16
votes
2answers
866 views

The process substitution output is out of the order

The echo one; echo two > >(cat); echo three; command gives unexpected output. I read this: How process substitution is implemented in bash? and many other articles about process ...
37
votes
2answers
20k views

Why does process substitution result in a file called /dev/fd/63 which is a pipe?

I am trying to understand named pipes in the context of this particular example. I type <(ls -l) in my terminal and get the output as, bash: /dev/fd/63: Permission denied. If I type cat <(ls -...
6
votes
1answer
2k views

Performance differences between pipelines and process substitution

I tend to use pipelines in my bash scripts over process substitution in most situations, especially in cases of using multiple sets of commands as it seems more readable to do ... | ... | ... over ... ...
24
votes
1answer
2k views

What is the portable (POSIX) way to achieve process substitution?

Some shells, like bash, support Process Substitution which is a way to present process output as a file, like this: $ diff <(sort file1) <(sort file2) However, this construct isn't POSIX and, ...
12
votes
2answers
2k views

How process substitution is implemented in bash?

I was researching the other question, when I realized I don't understand what's happening under the hood, what are those /dev/fd/* files and how come child processes can open them.
5
votes
1answer
1k views

Pipes vs process substitution

While trying the cat "$@" trick to read from either standard input or given files, it turned out that pipe and process substitution handle a missing trailing newline differently: printf %s foo > ...
3
votes
1answer
437 views

Process substitution and cat: can't read stdin

The process substitution <(cat) doesn't work. Why? head <(cat) cat: -: Input/output error I can use an extra file descriptor, but I don't understand why the above doesn't work. # Using file ...
11
votes
3answers
13k views

How do I use tee to redirect to grep

I don't have much experience of using tee, so I hope this is not very basic. After viewing one of the answers to this question I came across a strange beheviour with tee. In order for me to output ...
8
votes
4answers
1k views

Split an input for different command and combine the result

I know how to combine the result of different command paste -t',' <(commanda) <(commandb) I know pipe same input to different command cat myfile | tee >(commanda) >(commandb) Now how ...
11
votes
5answers
39k views

grep files from list

I am trying to run grep against a list of a few hundred files: $ head -n 3 <(cat files.txt) admin.php ajax/accept.php ajax/add_note.php However, even though I am grepping for a string that I know ...
11
votes
3answers
12k views

Failed to open config file '/dev/fd/63', error: No such file or directory for wpa_supplicant

When I do this: sudo wpa_supplicant -D nl80211,wext -i wlp4s0 -c <(wpa_passphrase "some ssid" "password") I get Successfully initialized wpa_supplicant Failed to open config file '/dev/fd/63', ...
0
votes
1answer
197 views

Using process substitution, only send stderr to process

I have this: exec > >( while read line; do echo " stdout: $line"; done ) exec 2> >( while read line; do echo " stderr: $line"; done ) echo "rolo" >&2 echo "cholo" if you run that ...
3
votes
4answers
2k views

How to open process substituted file from php?

Here's what I tried to do myself: $ type 1.sh #!/bin/bash -eu php -r 'var_dump(file_get_contents($_SERVER["argv"][1]));' -- <(echo 1) $ ./1.sh PHP Warning: file_get_contents(/dev/fd/63): failed ...
13
votes
2answers
956 views

Bash: process substitution and stdin

The following line is obvious: echo "bla" | foo | bar But does the ones below do the same? echo "bla" | bar <(foo) echo "bla" | bar < <(foo) Which of the foo and bar read "bla" from stdin ...
18
votes
4answers
2k views

bash: how to propagate errors in process substitution?

I want my shell scripts to fail whenever a command executed with them fails. Typically I do that with: set -e set -o pipefail (typically I add set -u also) The thing is that none of the above ...
6
votes
2answers
598 views

Combining multiple process substitution

Suppose you tried something like this: $ paste ../data/file-{A,B,C}.dat and realize that you want to sort each file (numerically, let's suppose) before pasting. Then, using process substitution, you ...
4
votes
2answers
760 views

How do you implement process substitution (using a bash script) in a shell that doesn't have it?

I've seen Fish shell implement process substitution as a function: # === Fish shell lang: function psub mkfifo $the_pipe cat >$the_pipe & echo $the_pipe # remove pipe when bg job ...
1
vote
1answer
403 views

Is the command in a process substitution invoked in a subshell?

From the bash manual Process substitution is supported on systems that support named pipes (fifos) or the /dev/fd method of naming open files. It takes the form of <(list) or >...
13
votes
1answer
840 views

How to emulate Process Substitution in Dash?

In bash, I can use Process Substitution and treat output of a process as if it was a file saved on disk: $ echo <(ls) /dev/fd/63 $ ls -lAhF <(ls) lr-x------ 1 root root 64 Sep 17 12:55 /dev/fd/...
5
votes
4answers
4k views

Why is there a “/dev/fd/63” in the output of “echo 123 >(cat)”?

$ echo 123 | cat 123 is doing what I expected, both commands run inside the same shell. But when I connect them with the >( ... ) expression, which connects the output of one command in the ...
4
votes
2answers
872 views

Putting process substituted file descriptor into variable

I have long command roughly this: $ command-outer "long command which references a file here: filename1, and another file reference here: filename2" The files are the output of another command. So I ...
3
votes
4answers
240 views

Why does `… | sed 's/^/stdout: /'` print on empty stdin when `… > >(sed 's/^/stdout: /')` doesn't?

I'm trying to understand what causes the difference in these 2 constructs that I thought were functionally equivalent: $ ( echo foo >&2 ) 2> >(sed 's/^/stderr: /') | sed 's/^/stdout: /' ...
3
votes
2answers
321 views

`tee` and `bash` process substitution order

I'd have supposed this code would have printed "oof" first: echo foo | tee >(rev) | ( sleep 1 ; cat ; ) Output: foo oof Increasing the sleep time doesn't change the order. Why doesn't that ...
0
votes
1answer
679 views

Subshell and process substitution

Apologies if this is a basic question - I'm stuck trying to solve a larger problem, and it's come down to how a shell script is invoked - directly (shellScript.sh) or using sh shellScript.sh. Here's ...
10
votes
3answers
414 views

When was process substitution first introduced?

I'm curios to know how long process substitution has been around. What shell first had it? When did it get added to other shells?
7
votes
4answers
1k views

Using process substitution to trick programs expecting files, with specific extensions as argument?

Here is my use case: the command line utility melt can accept a file name, with the extension .melt on the command line, and open it; as an example, this is a proper test_p.melt file: colour:blue out=...
5
votes
1answer
160 views

Why is the stdout of a `>()` subshell different if it's part of a redirection (e.g. `> >()`)?

This is a followup question to: Why does `... | sed 's/^/stdout: /'` print on empty stdin when `... > >(sed 's/^/stdout: /')` doesn't? To be more concrete, why is this a ...
5
votes
0answers
43 views

cat in process substitution hangs: what is it waiting for? [duplicate]

I have this piece of code using Process Substitution. When I run it, it works fine, but it does not exit - just hangs there waiting for input. Why and how to overcome? prepro() { in=$(<...
4
votes
1answer
1k views

How to read from stdin in process substitution? [duplicate]

I would like to send stdout to multiple commands, however I'm not sure how do I read from standard input within process substitution? My attempts: $ echo foo >(cat /dev/stdin) >(cat /dev/stdin)...
3
votes
1answer
86 views

non-deterministic output from independent processes run concurrently by process substitution

On bash v4.1.2(2), the following simple statement, chosen merely as a minimal example demonstrating the problem, gives seemingly random output: $ for n in {0..1000}; do echo "$n"; done | tee >(...
2
votes
3answers
654 views

Processing a single file as both input and output throughout pipes [duplicate]

Good evening, I would like to filter a file's content with some piped commands and then write the result back to the same file. I know, I can't do that the way I wrote it. Hold on … This is the ...
1
vote
1answer
2k views

Occasional error from bash on AIX: Interrupted system call

I am experiencing problems with process substitution in bash on AIX It happens very rarely, apparently only when the server is loaded. An example error message is: line 9: /tmp//sh-np-7841523: ...
1
vote
1answer
655 views

Scope of variables in a process substitution

I have a command which takes two arguments. Assume we want to create both arguments by process substitution: cat <(var=123; echo $var) <(echo $var) What has to be done, to make $var available ...
1
vote
1answer
110 views

Persistent process substitutions? [duplicate]

Is there a way to take a process substitution like <(grep foo some/file), and save it to a "file-like entity" on disk (reminiscent of a fifo), so that, every time this thing was opened for reading ...
0
votes
0answers
108 views

Bash Process Substitution Hangs When Listing Bindings

TLDR: cat <(INPUTRC=/dev/null bash -c 'bind -pm emacs') # freezes # I can't use this because I need to pipe the output of the bind cat <(INPUTRC=/dev/null bash -c 'bind -pm emacs' &) # ...
0
votes
0answers
37 views

Process substitution doesn't work with diff and node

I'm trying to compare the output of my fizzbuzz.js program: for (let i = 1; i <= 100; i++) { let out = ""; if (i % 3 == 0) out += "Fizz"; if (i % 5 == 0) out += "Buzz"; if (i % 3 &&...