home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!munnari.oz.au!metro!physiol.su.OZ.AU!john
- From: john@physiol.su.OZ.AU (John Mackin)
- Subject: Re: How to empty a file
- Message-ID: <1992Aug27.090806.18989@physiol.su.OZ.AU>
- Organization: Department of Physiology, University of Sydney, Australia
- References: <17g4kbINN4bm@seven-up.East.Sun.COM> <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>
- Date: Thu, 27 Aug 1992 09:08:06 GMT
- Lines: 36
-
- In article <1992Aug26.172228*Harald.Eikrem@delab.sintef.no>,
- Harald.Eikrem@delab.sintef.no writes:
-
- > 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".
- 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). Not all
- shells have that. One example of a shell that doesn't is rc. (I
- happen to define : as a null function in _my_ rc environment because
- I like to be able to mouse and resend lines even if I have something
- in the prompt... but that doesn't alter the fact that rc doesn't
- normally use : this way.)
-
- 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.
-
- As for someone's suggestion of "echo > target", I have to point
- out that many, indeed today probably most, versions of echo _do_
- print a newline when given no arguments.
-
- --
- John Mackin <john@civil.su.oz.au>
- `You ate WHAT?'
-