How to zero out a file in tcsh?

John Chambers jc at trillian.mit.edu
Fri Feb 7 12:55:07 EST 2003


Dave Gavin writes:
|  the "rm filename; touch filename" variation doesn't necessarily preserve
| ownership or permissions depending on who does it and what their umask is.
| My personal favorite is "cat /dev/null > filename".

This may be the most universal, and it doesn't have the problem  with
"rm;touch" of a window when the file doesn't exist. Is there any case
where this wouldn't work in any unix shell?

If you're worried about the  overhead  of  the  unnecessary  process,
there  doesn't  seem  to  be  any universal command that works in all
known shells.  Using echo doesn't quite work, because it  produces  a
single  \n  by  default, and there are at least two different ways of
suppressing this character.

Isn't it amazing how much discussion it can take to figure out how to
produce nothing, reliably?

I've always sorta liked the observation that the Arabs introduced the
concept  of  zero  to Western Civilization around 1500 years ago, but
most of the computer industry still hasn't caught on to the idea. The
zero case is almost always special, and takes special code to handle.
Unix software is usually better at this than others, but even on unix
systems  you  run  into lots of cases where making the zero case work
takes half the time.

I haven't worked on IBM mainframes for over 20 years now, but I  well
remember  the  grief  caused  by the fact that closing an output file
without writing a record was a fatal  error,  as  was  attempting  to
write a zero-length record.  This recently bit me again, though.  I'm
working on a project where some of the files get sent to  mainframes.
One of the constraints is that, if my code writes \n\n, the mainframe
(Cobol) software gets a fatal error when it attempts to deal with the
zero-length record. So far, I haven't sent them any null files, but I
can well imagine what that would do to their software.

Sigh.




More information about the Discuss mailing list