Can You please explain me why: 'cat < file.txt > file.txt ' makes file.txt empty ?
Tell me more
×
Super User is a question and answer site for
computer enthusiasts and power users. It's 100% free, no registration required.
migrated from stackoverflow.com Dec 21 '09 at 23:07
|
Because it opens and truncates the file before reading the data — it being shell, the redirections are processed by shell before even starting |
|||
|
|
|
The |
|||
|
file) you could typecat <file.txt >>file.txtas two >> mean appending to instead of deleting the file. – GregC Dec 22 '09 at 6:32