See the difference between
echo 'ls' | sh -s
and
( echo 'ls'; cat ) | sh -s
or,
{ echo 'ls'; cat; } | sh -s
Here, sh -s
will start a shell session that reads commands to execute from standard input (-s
).
In the first example, the shell will execute ls
and exit (since there's no more input).
In the second and third examples, the shell will execute ls
and wait until there's no more input. The input stream to sh -s
was first generated by the echo
command, but then cat
took over. The cat
process will read from the parent shell session and pass commands through the pipe to sh -s
. If you type ls
or any other commands (there will be no prompt to type it at), the shell will execute those commands.
This will continue until you terminate the cat
process by pressing Ctrl+D on an empty line to signal the end of input.
I believe that is what you mean by "keeping the pipe open".