You're really looking at what's termed flow control
, and/or (re)direction -- again; flow control
, or stdin
, stdout
(standard in / standard out).
I hope my above statement helps you better understand what's intended to occur, and what you can better expect.
pipe, or "piping" stdout
, merely directs stdout
in most cases.
Parallel is really another name for tandem. You can attempt to run 2 different/same commands/outputs at the same time. But expecting a synchronized run would be unwise, as it's unlikely to occur.
To your example; Here you introduce what's called a conditional. Much the same as a road sign, or a traffic light. These conditional(s) direct flow based on a condition. In your example, the while "condition" -- while this, do that. Conditions generally redirect stdin
, stdout
.
In direct answer to your 2 direct questions
- Does pipe run in parallel
No. not necessarily. At least not in the normal sense of "parallel" (tandem).
But pipe
can fire (initiate) 2 jobs at the same time. Even the same job twice.
- How pipe and redirection work "under the hood" ?
I hope I've better illustrated that for you above. :)
or
cat ./ASCII | grep somename >./output
The above cat ./ASCII
is output (stdout
). Which becomes input (stdin
) by way of pipe (|
) for grep somename
. Which is (re)directed (>
) to its final output ./output
.
cmd1 | cmd2
cmd1 will execute and stdout will be shared with stdin of cmd2.” But that doesn’t make any statement about whether the commands will run at the same time or consecutively...?