6600tom@ucsbuxa.ucsb.edu (Thomas Kwong) (12/27/90)
In the final exam ( Unix and C ) that I just take, one UNIX problem is like this: %cat myfile word1 word2 word3 word4 word5 word6 %wc myfile 3 6 36 myfile %wc myfile > myfile %cat myfile 0 0 0 myfile How come MYFILE becomes that? I think it should be like: 3 6 36 myfile because output of wc myfile is redirected to myfile. Can anybody tell me why? Thomas Kwong. ------------------------------ 6600tom@ucsbuxa.ucsb.edu
sfreed@ariel.unm.edu (Steven Freed CIRT) (12/28/90)
>%wc myfile > 3 6 36 myfile > >%wc myfile > myfile >%cat myfile > 0 0 0 myfile > >How come MYFILE becomes that? because the original "myfile" gets overwritten by the new "myfile" (from the redirection) by the shell BEFORE wc is run, therefore, the only thing wc sees is an empty file. -- Thanks, Steve. sfreed@ariel.unm.edu