Aside from using a temporary file to help, is there a way/program could buffer input from stdin
but does not output the contents until getting the EOF
. I don't want to use a shell variable either(e.g. buffer=$(cat)
).
This program should behave as below(assume the program name is buffered-cat
):
$ buffered-cat
line 1
line 2
line 3
^D # Ctr-D here(End of Line)
Now that the program received ^D
, the buffered-cat
outputs the contents
line 1
line 2
line 3
sort
for this purpose. Obviously it has side-effects that may be undesirable.