Question Re: [svlug] copying special files to VFAT

J C Lawrence claw at kanga.nu
Tue Nov 13 21:18:01 PST 2001


On Sat, 10 Nov 2001 14:51:27 -0800 
Mark S Bilk <Mark> wrote:
>> From: J C Lawrence <claw at kanga.nu> Date: Sat, 10 Nov 2001
>> 12:29:19 -0800
>> On Sat, 10 Nov 2001 08:48:26 -0800 Marc MERLIN
>> <marc_news at valinux.com> wrote:
 
>>> I can write a perl script to study the filenames and rename them
>>> before the copy, but I was hoping for something a bit simpler
>>> than that, like a mount option for the vfat partition that
>>> discards forbidden characters (I looked in the options, but none
>>> seemed to do that).

>> For a slightly similar problem I do the following.

>> First script the copy tool ala:

>> mpycp: cp ${2} ${1}`echo ${2} | echo $dir | sed s./.\\\!.g`

> I assume this specifies a file called "mycp" containing:

Err, something like that.  A core problem is that I wrote the
referenced message quickly and wildly cut'n'pasted things from
fairly specific scripts I have/use here into the more general form
without checking their details.

> When "doit pattern destdir" is run, "find" searches for all the
> files under / that match "pattern", and sends each path/filename
> to xargs, which makes multiple calls of "mycp destdir
> path/filename".

Yep.

> I'm interpreting the second argument of doit to be the ultimate
> destination directory by its usage in mycp.  The only problem with
> doit is that if pattern equals '*', and even if it's escaped with
> \ or protected with ' ' in the call to doit, it still gets globbed
> when the doit script runs, causing "find" to get multiple
> arguments after "-name", and to fail with a confusing error
> message about the paths needing to precede the expression.  To fix
> this I had to either precede the "find" line with "set -o noglob",
> or change it to

<checks quickly>

Hehn.  You're right.  I've just never hit that as I always run it
against regexes which don't match anything in the current directory.

>    find / -name "${pattern}" | xargs -n1 mycp ${path}

> That's just expected tweaking, but mycp has bigger problems.

>    cp ${2} ${1}`echo ${2} | echo $dir | sed s./.\\\!.g`cp ${2} ${1}`echo ${2} | echo $dir | sed s./.\\\!.g`

> This is the source of the most confusion for me.  Apparently the
> second argument of cp is supposed to be the destination directory
> ${1} (the mountpoint of the VFAT filesystem), followed by the
> path/filename of the source file, as modified by the sed command.
> But "echo $dir" yields nothing, 

Bad paste on my part.  Corrected (as you later propose):

  cp ${2} ${1}`echo ${2} | sed s./.\\\!.g`

> ... because even if $dir were some predefined variable (which it
> doesn't seem to be) the echo command totally ignores its standard
> input.  Therefore sed gives no output, and the second argument of
> cp is just the destination directory, putting all the files into
> the root of the VFAT filesystem.  Does echo take standard input on
> your system?  Are you using some other shell than bash, with a
> builtin echo command that has different features?

Nahh, just a silly error.

> Finally, if "| echo$dir" is deleted, the sed command converts all
> the '/' in the source path into '!' in the destination path.

Yep, that's the purpose of it.  I do this specifically as I have a
bit of elisp under XEmacs that keeps historical versions of all the
files I edit with their full paths in this form (it internally
translates all the slashes to exclams and writes that to my
~/.backups directory).

> What's that for?  Was the first '/' in the sed command meant to be
> ':' in order to change ':' into '!' as the poster requested?

Marc could do that to be sure.  I wasn't attempting to solve his
specific case but to show a more general case which pertained to his
(that of collapsing a directory hierarchy's files into a single
directory without losing any path info.  As that requires
translating the path characters, a similar pattern can be used for
protecting/changing the colons.

-- 
J C Lawrence
---------(*)                Satan, oscillate my metallic sonatas.
claw at kanga.nu               He lived as a devil, eh?
http://www.kanga.nu/~claw/  Evil is a name of a foeman, as I live.




More information about the svlug mailing list