ls > ls.out
this will include ls.out in the list too. My understanding is: > (shell output redirection operator is creating a file first (to take the STDOUT) if it is not already existing and then ls command is coming to play and it is including the just created ls.out file in the output. Is this correct? If not, can you please elaborate the workings of that command.
Similarly
wc temp > temp
Will print 0 0 0 temp inside the just created temp file.
This behavior of shell is interesting. I wonder, how it is actually working. BTW, both are exercises in The Unix Programming Environment Book. As I mentioned the answer above, I want some expert to correct my understanding.