home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3677 < prev    next >
Encoding:
Text File  |  1992-08-29  |  1.7 KB  |  47 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!munnari.oz.au!metro!physiol.su.OZ.AU!john
  3. From: john@physiol.su.OZ.AU (John Mackin)
  4. Subject: Re: How to empty a file
  5. Message-ID: <1992Aug27.090806.18989@physiol.su.OZ.AU>
  6. Organization: Department of Physiology, University of Sydney, Australia
  7. References: <17g4kbINN4bm@seven-up.East.Sun.COM> <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>
  8. Date: Thu, 27 Aug 1992 09:08:06 GMT
  9. Lines: 36
  10.  
  11. In article <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>,
  12.     Harald.Eikrem@delab.sintef.no writes:
  13.  
  14. > This is definitely a FAQ.  My favourite file making/nulling command is:
  15. >
  16. >  : > file
  17. >
  18. > which should work from any kind of shell (in csh "noclobber" must be
  19. > neutralised).
  20.  
  21. Wrong again.  Nothing says this "should work from any kind of shell".
  22. It will work from any kind of shell that has : as a functional comment
  23. character (or, if you want to look at it that way, as a builtin
  24. command that ignores its arguments and doesn't do anything).  Not all
  25. shells have that.  One example of a shell that doesn't is rc.  (I
  26. happen to define : as a null function in _my_ rc environment because
  27. I like to be able to mouse and resend lines even if I have something
  28. in the prompt... but that doesn't alter the fact that rc doesn't
  29. normally use : this way.)
  30.  
  31. If you really want something that "should work from any kind of
  32. shell", and you aren't happy with "cat /dev/null >target", then
  33. use
  34.  
  35.     sh -c '> target'
  36.  
  37. All that depends on is that you have sh, and that single quotes
  38. work as expected in the shell in use.
  39.  
  40. As for someone's suggestion of "echo > target", I have to point
  41. out that many, indeed today probably most, versions of echo _do_
  42. print a newline when given no arguments.
  43.  
  44. -- 
  45. John Mackin <john@civil.su.oz.au>
  46. `You ate WHAT?'
  47.