hello all,
I was playing around with the following commands:
Firstly I created a test.txt file and I wrote the days in order. One day per line. Then I opened the terminal and I did:
Code:
$ sort test.txt
As it was expected I got:
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
Then I did:
Code:
$ sort test.txt >> test.txt
Again as it was expected I got into the test.txt the following content:
Monday
Tuesday
Wednesday
Thursday
Friday
Saturday
Sunday
Friday
Monday
Saturday
Sunday
Thursday
Tuesday
Wednesday
Then I decided to try and overwrite the contend with only the sorted list:
Code:
$ sort test.txt > test.txt
Unexpectedly I got an empty file :p
I know I could transfer the sorted list to a new file and then overwrite the content of the test.txt file with the content of the new file.. And finally delete the new file.
But my question is why bash couldn't overwrite directly the content of the test.txt and as a result I got an empty file?
Thanks in advance