This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

A more interesting question (yet slightly more pedantic) would be to know if the evaluation order is defined in POSIX or is it implementation-specific.
–
rahmuJun 20 '12 at 18:19

@rahmu - True. I happen to be using zshell on OSX Lion.
–
Nathan LongJun 20 '12 at 18:21

1

@rahmu POSIX does specify the order but it doesn't need to because if you think about it for just a moment, you'll realize that the shell is the one that does the redirections and it has to do them before running the command, since it will be too late to do it after the command has already started. Add that bit of common sense to the fact that the > operator includes truncation and this behavior becomes very logical.
–
jw013Jun 20 '12 at 21:55

Because the shell that you use to invoke cat does the redirection indicated by >.

The shell (bash, zsh, ksh, dash, whatever) reads the command cat foo.txt > foo.txt. The shell has to set up the redirection indicated by > foo.txt. > means to start writing the file from the top, >> would mean to append to foot.txt.

By the time the shell actually gets cat running, foo.txt has disappeared.