This question already has an answer here:
I know this is sort of a duplicate of another question (Why this sort command gives me an empty file?) but I wanted to expand on the question in response to the answers given.
shuf example.txt > example.txt
Returns a blank file, because the shell truncates the file before shuffling it, leaving only a blank file to shuffle. However,
cat example.txt | shuf > example.txt
will produce a shuffled file as expected.
Why does the pipeline method work when the simple redirection doesn't? If the file is truncated before the commands are run, shouldn't the second method also leave an empty file?