This question already has an answer here:
When you try to sort a file in-place with
sort afile > afile
you silently end up with
afile being an empty file.
Why is that? I'd expect either an error or the original contents, but sorted. I haven't tested other shells.
Upvotes for one-liners that do perform the expected behaviour.
PS bash redirect input from file back into same file doesn't address the "why" at all. I know I can go around it with a temporary file. I am interested in what happens. The upvotes for one-liners part was an afterthought in search of shorter ways.