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

Re: A-posteriori use of another HDD for the /home/username



In <[🔎] 87fx6mkfhn.fsf@merciadriluca-station.MERCIADRILUCA>, Merciadri Luca wrote:
>$ cp *.*
>is equivalent to
>$ cd . ; cp *

Not true.

The second misses a file named "foo", as the shell glob "*.*" only matches 
filenames with at least one '.' character in their name.

>$ cp .*
>is equivalent to
>$ cd . ; cp *

Again, not true.

The second misses a file named ".foo", as wildcards ('?' and '*' characters) 
in shell globs do not match a '.' character in the first position.  (This is 
part of the "hidden" aspect of dot-files.)

>A third case is
>$ cp .[a-zA-Z0-9]*
>which is equivalent to copy everything beginning with a dot, and
>ending with whatever you can imagine.

Again, not true.

The first misses a file named ".$ntfs$protected", as the bracket/range 
expression only catches letters and digits, and may not catch all of them 
depending on the collation settings in the environment.

>Consequently, using
>$ cp .[a-zA-Z0-9]*
>
>and the mere (after or before)
>$ cp *
>
>should copy all the files of a directory to another (they were
>evidently not specified here, as it is trivial stuff).

I would use (cp {,.[!.]}* "$destination") in shells that do brace expansion 
before filename expansion ("globbing"), e.g. bash and zsh.  In other shells, 
e.g. those without brace expansion, I would write it out as (cp * .[!.]* 
"$destination").

An alternative I got in the habit of using instead of remembering the "line 
noise" above is doing (cp -r "$src/." "$destination"), which is, for me, 
semantically closer to what I *mean* than writing something that expands to 
all the entries in the directory.

>I could be wrong for at least one of these facts. If so, we can
>discuss on it. The syntax is actually weird when one begins to play
>with special files. For sure.

The various expansions done by the shell and the order they are done in is 
well-documented by the bash info pages, the zsh man pages, and (for POSIX-
compliant shells) the Single Unix Specification.

They are not necessarily easy to understand, but I wouldn't use the word 
"weird".  I think "complex" is a better adjective.
-- 
Boyd Stephen Smith Jr.                   ,= ,-_-. =.
bss@iguanasuicide.net                   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy         `-'(. .)`-'
http://iguanasuicide.net/                    \_/

Attachment: signature.asc
Description: This is a digitally signed message part.


Reply to: