Solution 1:
<command_which_produces_output> | { a="$(</dev/stdin)"; echo "$a"; echo "$a"; }
This way you save the contents from standard input to a (choose the best name, please) and then echo 'twice.
Note $(</dev/stdin) is a similar but more efficient way to make $(cat /dev/stdin) .
Solution 2:
Use tee as follows:
<command_which_produces_output> | tee >(echo "$(</dev/stdin)")
Here you first write to the standard output (what tee does), and also writes to the FIFO file created by the process substitution :
>(echo "$(</dev/stdin)")
See, for example, the file that it creates on my system:
$ echo >(echo "$(</dev/stdin)") /dev/fd/63
Now the echo "$(</dev/stdin)" is what I found, first of all, to read the entire file before printing it. This echo is the content read from the standard process substitution input, but as soon as all the input is read (not like cat , which prints in turn).
whoan source share