I'm a new Linux user and I was doing some experiments and trying to understand Process Substitution. I believe I already have a basic understanding of it. But here is a case that I don't know why. I'm using Bash on Ubuntu 20.04.
echo hi
just sends the string hi
with a newline character to stdout.
root@u2004:~# echo hi | od -a
0000000 h i nl
0000003
root@u2004:~#
cat
can read from the pipeline as its stdin, and send what it read down to the pipeline.
root@u2004:~# echo hi | cat
hi
root@u2004:~# echo hi | cat | od -a
0000000 h i nl
0000003
root@u2004:~#
As I understand, the command echo hi > >(cat)
will also make cat
read from its stdin (and print to the console). But when I run it, I got this:
root@u2004:~# echo hi > >(cat)
root@u2004:~# hi
<the cursor blinks at this location>
I have to press the Enter key to finish the command.
root@u2004:~# echo hi > >(cat) root@u2004:~# hi Enter root@u2004:~#
Why this behavior? Is my understanding of the command echo hi > >(cat)
correct?
echo hi > >(sleep 1; cat)
. I guess the race was not fair on my box. – thanasisp May 09 '22 at 23:05