Starting from here I tried to read a file and emit the head and the tail of the file (reading the file only once).
I tried the following:
tee >(head) >(tail) > /dev/null < text.txt
This line works as expected, but I'd like to get rid of the /dev/null. So I tried:
tee >(head) | tail < text.txt
But this line does not work as expected (well, as I expected), it prints the head but does not return after that. Apparently tail is waiting for something. But I don't know what for exactly. I found this SO question, but I could not get it running with the given answers.
In
tee >(head) | tail < text.txt
, the text file goes directly totail
. You probably meantWhich does not wait for anything, but does not work either, because the output of both tee and head go to tail.
Redirecting the head's output to a new file descriptor and then taking it back works, but I am not sure it is "cleaner" than using /dev/null: