home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!mcsun!sunic!ugle.unit.no!news
- From: Harald.Eikrem@delab.sintef.no
- Subject: Re: How to empty a file
- In-Reply-To: john@physiol.su.OZ.AU's message of Thu, 27 Aug 1992 09:08:06 GMT
- Message-ID: <1992Aug29.125306*Harald.Eikrem@delab.sintef.no>
- Sender: news@ugle.unit.no (NetNews Administrator)
- Organization: SINTEF DELAB, Trondheim, Norway.
- References: <17g4kbINN4bm@seven-up.East.Sun.COM>
- <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>
- <1992Aug27.090806.18989@physiol.su.OZ.AU>
- Date: 29 Aug 92 12:53:06
- Lines: 52
-
- john@physiol.su.OZ.AU (John Mackin)'s correction to something I said:
- ! > This is definitely a FAQ. My favourite file making/nulling command is:
- ! >
- ! > : > file
- ! >
- ! > which should work from any kind of shell (in csh "noclobber" must be
- ! > neutralised).
- !
- ! Wrong again. Nothing says this "should work from any kind of shell".
- ^^^^^^^^^^^
-
- Does this imply that most things I say is "wrong" in your eyes?
-
- ! It will work from any kind of shell that has : as a functional comment
- ! character (or, if you want to look at it that way, as a builtin
- ! command that ignores its arguments and doesn't do anything).
-
- Yeah, the `:' command was meant to be a null command (do nothing, or
- "noop" as some ancient assembler languages probably would have it) which
- in the normal case returned status 0, exactly like the functional effect
- of the `true' command, except `:' is a builtin. The shell still expands
- variables and performs i/o redirects. However, in csh (and tcsh) the `:'
- command is only useful for doing redirects, it will not accept arguments,
- which is a pity.
-
- ! Not all shells have that. One example of a shell that doesn't is rc.
-
- So why did the designers/implementors of rc chose not to make `:' a null
- command? Is there a null command in rc?
-
- ! If you really want something that "should work from any kind of
- ! shell", and you aren't happy with "cat /dev/null >target", then
- ! use
- !
- ! sh -c '> target'
- !
- ! All that depends on is that you have sh, and that single quotes
- ! work as expected in the shell in use.
-
- In lack of :, the simplest *general* file nulling command should be
-
- true > file
-
- or, in lack of a `true' command:
-
- sh -c : > file
-
- :> :> :)
-
- Enough of this.
-
- ~~harald E.
-