home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / unix / question / 14753 < prev    next >
Encoding:
Text File  |  1992-12-16  |  1.5 KB  |  50 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
  3. From: navarra@casbah.acns.nwu.edu (John Navarra)
  4. Subject: cat a > a , getting it straight
  5. Message-ID: <1992Dec17.020805.28043@news.acns.nwu.edu>
  6. Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
  7. Nntp-Posting-Host: unseen1.acns.nwu.edu
  8. Organization: Northwestern University, Evanston Illinois.
  9. Date: Thu, 17 Dec 1992 02:08:05 GMT
  10. Lines: 38
  11.  
  12.  
  13. I have a question on shell redirection. If I do 
  14. $ cat a > a 
  15.  
  16. I get a warning message from cat saying that the input file is the same as
  17. the output. As I understand it, when a shell opens a file for redirection,
  18. it truncates its length to zero. Thus, you wind up cat'ing a zero length
  19. file to a zero-length file. Result: your original file was blown away.
  20. Similarly, if I do
  21. $ wc a > a
  22. $ cat a
  23. 0       0       0 a
  24.  
  25. wc gives me the result I expect.
  26.  
  27. Now, if I do:
  28. $ cat a
  29. file a
  30. $ cat a >> a
  31. cat: input a is output
  32. $ cat a
  33. file a        #why aren't there two lines of 'file a'?
  34. $ wc a >> a
  35. $ cat a
  36. file a
  37.        1       2       7 a
  38.  
  39. Why does appending a to a with cat not work but wc a >> a does produce
  40. the output from wc that is expected?  
  41.  
  42. confused just a little,
  43. -tms
  44.  
  45. -- 
  46. You can get further with a kind word | You can get further with a kind word
  47. and a gun than a kind word alone.    | and a phaser than a kind word and a gun.
  48.           --al capone                |           -- John Navarra
  49. =======From the Lab of the MaD ScIenTIst....navarra@casbah.acns.nwu.edu========
  50.