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

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!mcsun!sunic!ugle.unit.no!news
  3. From: Harald.Eikrem@delab.sintef.no
  4. Subject: Re: How to empty a file
  5. In-Reply-To: john@physiol.su.OZ.AU's message of Thu, 27 Aug 1992 09:08:06 GMT
  6. Message-ID: <1992Aug29.125306*Harald.Eikrem@delab.sintef.no>
  7. Sender: news@ugle.unit.no (NetNews Administrator)
  8. Organization: SINTEF DELAB, Trondheim, Norway.
  9. References: <17g4kbINN4bm@seven-up.East.Sun.COM>
  10.     <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>
  11.     <1992Aug27.090806.18989@physiol.su.OZ.AU>
  12. Date: 29 Aug 92 12:53:06
  13. Lines: 52
  14.  
  15. john@physiol.su.OZ.AU (John Mackin)'s correction to something I said:
  16. ! > This is definitely a FAQ.  My favourite file making/nulling command is:
  17. ! >
  18. ! >  : > file
  19. ! >
  20. ! > which should work from any kind of shell (in csh "noclobber" must be
  21. ! > neutralised).
  22. ! Wrong again.  Nothing says this "should work from any kind of shell".
  23.   ^^^^^^^^^^^
  24.  
  25. Does this imply that most things I say is "wrong" in your eyes?
  26.  
  27. ! It will work from any kind of shell that has : as a functional comment
  28. ! character (or, if you want to look at it that way, as a builtin
  29. ! command that ignores its arguments and doesn't do anything).
  30.  
  31. Yeah, the `:' command was meant to be a null command (do nothing, or
  32. "noop" as some ancient assembler languages probably would have it) which
  33. in the normal case returned status 0, exactly like the functional effect
  34. of the `true' command, except `:' is a builtin.  The shell still expands
  35. variables and performs i/o redirects.  However, in csh (and tcsh) the `:'
  36. command is only useful for doing redirects, it will not accept arguments,
  37. which is a pity.
  38.  
  39. ! Not all shells have that.  One example of a shell that doesn't is rc.
  40.  
  41. So why did the designers/implementors of rc chose not to make `:' a null
  42. command?  Is there a null command in rc?
  43.  
  44. ! If you really want something that "should work from any kind of
  45. ! shell", and you aren't happy with "cat /dev/null >target", then
  46. ! use
  47. !     sh -c '> target'
  48. ! All that depends on is that you have sh, and that single quotes
  49. ! work as expected in the shell in use.
  50.  
  51. In lack of :, the simplest *general* file nulling command should be
  52.  
  53.    true > file
  54.  
  55. or, in lack of a `true' command:
  56.  
  57.    sh -c : > file
  58.  
  59. :> :> :)
  60.  
  61. Enough of this.
  62.  
  63.   ~~harald E.
  64.