How to do <cmd> file | hold file (now cp)

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Tue Sep 11 23:47:22 AEST 1990


In article <1990Sep11.040043.14727 at chinet.chi.il.us> les at chinet.chi.il.us (Leslie Mikesell) writes:
> In article <15472:Sep1015:27:3190 at kramden.acf.nyu.edu> brnstnd at kramden.acf.nyu.edu (Dan Bernstein) writes:
> >Of course the editor should use write-over, as it's conceptually
> >modifying the *same* file. cp is putting a *different* file into the
> >name previously used for the original.
> Ah, but cp should only replace the *contents of the file*.

No. That is not what cp does. cp copies a file with one name into a new
file with a different name. The shell's > is what you use to replace the
contents of a file.

> The other
> semantics associated with a file (i.e the contents of the inode) are
> associated with the name, which is not being changed.

What are you talking about? The filename has absolutely nothing to do
with the contents of the inode; it's just a way of finding the inode.
Have you forgotten about hard links?

> A program that associates the same name with a different inode or different
> inode attributes might be a useful thing, but it shouldn't be called cp
> (at least not in something that claims to be unix).

Huh? ln is the program that associates a name with a different inode. cp
shouldn't be described this way at all; it associates (a copy of) a
file's contents with a new name. If there's already an association
between that new name and a different file, then cp should either fail
or sever the original association. It most certainly should not preserve
the original association when it's talking about an entirely new file.

Let me put it this way: If you had two programs, cp (copy) and rp
(replace), the first with unlink/create and the second with over-write,
which would you end up using almost all the time? The only time the
semantics of rp would be proper would be when you really were replacing
the old version of a file with a new version---but there's a program
called ``install'' that was designed to do this job.

---Dan



More information about the Comp.unix.shell mailing list