Shell: GNU BASH
I've been using the following command for a while now:
echo "$(fmt -w 50 < foo.txt)" > foo.txt
Without any issues. However, when I try:
fmt -w 50 < foo.txt > foo.txt
The file foo.txt gets turned into a blank file. I assume that this is because of something to do with precedence of redirection operators and subshells being parsed by the shell.
Searching the GNU BASH manual hasn't been very fruitful. Could someone please tell me if I missed something in the manual? I would really like to understand the reason for this behaviour so I can make further use of it and know about any cases where it might lead to trouble.