Why doesn’t “sort file1 > file1” work?
As other people explained, the problem is that the I/O redirection is done before the sort command is executed, so the file is truncated before sort gets a chance to read it. If you think for a bit, the reason why is obvious – the shell handles the I/O redirection, and must do that before … Read more