home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.questions
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!casbah.acns.nwu.edu!navarra
- From: navarra@casbah.acns.nwu.edu (John Navarra)
- Subject: cat a > a , getting it straight
- Message-ID: <1992Dec17.020805.28043@news.acns.nwu.edu>
- Sender: usenet@news.acns.nwu.edu (Usenet on news.acns)
- Nntp-Posting-Host: unseen1.acns.nwu.edu
- Organization: Northwestern University, Evanston Illinois.
- Date: Thu, 17 Dec 1992 02:08:05 GMT
- Lines: 38
-
-
- I have a question on shell redirection. If I do
- $ cat a > a
-
- I get a warning message from cat saying that the input file is the same as
- the output. As I understand it, when a shell opens a file for redirection,
- it truncates its length to zero. Thus, you wind up cat'ing a zero length
- file to a zero-length file. Result: your original file was blown away.
- Similarly, if I do
- $ wc a > a
- $ cat a
- 0 0 0 a
-
- wc gives me the result I expect.
-
- Now, if I do:
- $ cat a
- file a
- $ cat a >> a
- cat: input a is output
- $ cat a
- file a #why aren't there two lines of 'file a'?
- $ wc a >> a
- $ cat a
- file a
- 1 2 7 a
-
- Why does appending a to a with cat not work but wc a >> a does produce
- the output from wc that is expected?
-
- confused just a little,
- -tms
-
- --
- You can get further with a kind word | You can get further with a kind word
- and a gun than a kind word alone. | and a phaser than a kind word and a gun.
- --al capone | -- John Navarra
- =======From the Lab of the MaD ScIenTIst....navarra@casbah.acns.nwu.edu========
-