Running GNU bash, version 4.3.11(1)-release (x86_64-pc-linux-gnu).
I don't really understand process substitution (ProcSub) from the perspective of a user interested in lifting the hood on i/o processing and related speed issues. I use ProcSub to script, so I have some knowledge of File Descriptors 0,1,2, but that's pretty much it. I have read a few pretty good posts, e.g. [1], and misc. wikis, e.g. [2],[3], the latter stating: "Process substitution feeds the output (FD 1 and/or 2) of a process (or processes) into the stdin (FD 0) of another process". By that simplest of definitions and for just one process, it seems operationally no different from a simple unnamed pipe.
To look into that I started with tee
, in itself interesting from the point of view of i/o.tee
permits feeding "stdin to stdout and also to any files given as argument". So :
$ for i in 1 2 3; do (( j=i+10 )); printf "%d\n" $j > file_$i; done
# so each file in file_{1,2,3} contains the numeral in its name + 10.
$ cat file_{1,2,3} | tee file_4
11
12
13
$ cat file_4
11
12
13
Obviously, I am not interested in seeing data filling my screen ala Matrix, so when:
1) I add a pipe and redirection of shasum
's output ...
$ cat file_{1,2,3} | tee file_4 | shasum -a 256 > file_4.sha256
$
the one liner above exits quietly, file_4 is as before (above) and file_4.sha256 contains the computed SHA256 sum.
The above is just an example to illustrate my question, trying to understand intermediate i/o's. My layman's conclusion is that tee
saves the output of the cat
cmd in file_4 and its copy normally sent to stdout is actually not sent to stdout but piped to shasum
.
Q: Is this even remotely right ?
2) I try the same with ProcSub:
$ cat file_{1,2,3} | tee file_4 >(shasum -a 256 > file_4.sha256)
11
12
13
$
-> No stdout redirection of whatever being sent to FD 1 by tee
?
Q: I am not clear on what ProcSub does or does not do to i/o (obviously it does not affect i/o in this case) and could use an explanation of its mechanism.
3) I try with ProcSub and redirection of final stdout to file_4:
$ cat file_{1,2,3} | tee >(shasum -a 256 > file_4.sha256) > file_4
$
Again this time the one-liner exists quietly.
Q: So the general question is: how are i/o processed for the 3 cases above (or at least for the second and third) ? There are obvious and visible differences in i/o terms (just looking at final stdout), but sometimes different i/o processes can lead to identical end-results on the display. Tx.
<(...)
construct won't work in the third case. – Kira Jan 15 '16 at 16:34>(...)
, and I do not see anything in the question that would tell me that it does not work. – Hauke Laging Jan 15 '16 at 19:00$ tee < <(shasum -a 256 filename1) filename2
. You can even write my 3rd example as: `$ tee < <(shasum -a 256 <(cat file_{1..3})) > file_4. Nesting of process expansions is allowed. It can rapidly become a bit muddled though. Did I understand yr question correctly ? – Cbhihe Jan 19 '16 at 13:45