prova1 is a file with some text. When I run this code prova1 become empty:
sort prova1 > prova1
I know that to achieve the effect I can do:
sort prova1 -o prova1
I would just know the reason :)
prova1 is a file with some text. When I run this code prova1 become empty:
sort prova1 > prova1
I know that to achieve the effect I can do:
sort prova1 -o prova1
I would just know the reason :)
This is because the redirection is carried out first: >prova1 truncates your file so that the sort finds nothing. sort prova1 > prova1_sorted would work as you expect.
-ooption probably works around this by creating a temporary file, the same as sed's-ioption. – evilsoup Oct 24 '13 at 17:19