2

This answer shows numerous ways to stream multiple commands into another command, but since they use subshells you can't do stdin.

While you can achieve this with named pipes, it's somewhat ugly and can leave leftover processes afterwards:

$ mkfifo p
$ while :; do sleep 5s; echo save; done > p &
$ cat p > output &
$ cat </dev/stdin > p
test
asdf
woot
^C
$ cat output
save
test
asdf
save
save
woot
save
$ jobs
[1]-  Running                 while :; do
    sleep 5s; echo save;
done > p &
[2]+  Running                 cat p > output &

Is there a way to pull this off in a single command? Ideally I would like something along the lines of:

someutil <(while :; do sleep 5s; echo save; done) /dev/stdin > output

This way I can pipe the output to another command instead of a file.

J V
  • 173
  • 4

0 Answers0