ls | cat
- the stdout of
ls (its fd 1) will be the writing end of a pipe (or socketpair with ksh93 on some systems).
- the stdin of
cat (its fd 0) will be the reading end of that same pipe
- both commands will run concurrently (are started at the same time in separate processes)
- stdin of
ls is not affected (question 1)
- stdout of
cat is not affected (question 1)
- stderr (fd 2) of
cat are not affected (question 2).
ls's stderr also go to the writing end of the pipe (so
cat can read it from its stdin at the other end of the pipe), you can do:
ls 2>&1 | cat
Which says: "make fd 2 point to the same resource as that on fd 1 (here the pipe)"
bash 4.0 or above, you can also write it:
ls |& cat
On systems where pipes are bi-directional, you could do:
ls <&1 | cat >&0
cat's stdout be fed back to
ls via that same pipe but in the reverse direction, but that would be pointless as
ls never reads from its stdin.
On Linux, where pipes are not bidirectional, that command would give an error.