[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: cp and "blah/." or "." as a source

From: Eric Blake
Subject: Re: cp and "blah/." or "." as a source
Date: Tue, 05 Dec 2006 06:53:55 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv: Gecko/20061025 Thunderbird/ Mnenhy/

Hash: SHA1

According to Zak on 12/4/2006 4:45 PM:
> OK, but the -R (or maybe -r), which is I guess what I really meant,
> might be specified by POSIX.  If only the standard were free I'd have a
> read and see.

For cp, both -r and -R are documented by POSIX, although -r is left
unspecified (its traditional behavior on pipes and devices was less than
desirable).  And POSIX _is_ free - you can register to become a member of
the Austin group at no cost, and browse the 2004 corrections to the 2001
edition of POSIX online:

And yes, GNU 'cp -R' complies with POSIX:

>> It should not matter whether you spell the source as 'src/.' or the
>> shorter 'src', since both spellings name the same hierarchy.
> That's my point.  I suspect it shouldn't matter, but it does.  If you
> say "src" or "src/" you get one behaviour, but if you say "src/." you
> get another, despite the fact that they name the same directory.

Indeed, POSIX requires the following behavior (well, POSIX doesn't require
- -v, but it is useful for seeing what -R does):

$ mkdir demo demo/src demo/dest1 demo/dest2 demo/dest3
$ cd demo
$ touch src/a src/.a
$ cp -vR src dest1
`src' -> `dest1/src'
`src/.a' -> `dest1/src/.a'
`src/a' -> `dest1/src/a'
$ cp -vR src/ dest2
`src/' -> `dest2/src'
`src/.a' -> `dest2/src/.a'
`src/a' -> `dest2/src/a'
$ cp -vR src/. dest3
`src/./.a' -> `dest3/./.a'
`src/./a' -> `dest3/./a'

The key here is that POSIX talks about "each file in the file hierarchy
rooted in each source_file", with the destination being "the concatenation
of target, a slash character, and the pathname of the file relative to the
directory containing source_file".  The directory containing "src" or
"src/" is ., but the directory containing "src/." is src.

- --
Life is short - so eat dessert first!

Eric Blake             address@hidden
Version: GnuPG v1.4.5 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org


reply via email to

[Prev in Thread] Current Thread [Next in Thread]