Re: How do I get a list of filenames with spaces on bash?



On Thu, 24 Jan 2008 11:04:29 -0600, Ed Morton wrote:
[...]
cp -- "$f" "$n" &&
rm -- "$f"
[...]
Why not mv? cp won't work great for non-regular files.

To ensure that in the event of a failure the original file is unaffected.

in that case, mv doesn't affect the file not even its inode, it
affects the current directory, it's just a rename. A failing
rename just leaves things as they are. A failing cp may leave an
unfinished copy around.

Also note that cp may not preserve file attributes like
permissions, ACLs, ownership, time stamps... (see -p option for
some of those).


A better way to avoid overwriting files is to use the -i option
of cp/mv. See also (set -C; cat < in > out)

"cp -i" can still fail if the target file is unwritable and any use of "-i"

Yes, which is the intention, if the target file exists, writable
or not, you want cp to fail.

means you have to sit around while the scripts running which may not be desirable.
[...]

If the answer is always no, then:

cp -i -- "$f" "$n" <> /dev/null 2>&0

But the problem is that "cp" may not return a non-zero exit
status if the file is not copied (POSIX is ambiguous about that
and at least GNU and Solaris cp return 0 if the user doesn't
answer yes), so cat with set -C may be a better solution.

--
Stephane
.



Relevant Pages

  • Re: How can I do a 100% bullet proof Save?
    ... the save process itself failing is one in a million and the chance of either ... 'bad result' of a wrongly named original file after a failed save, ... > point of failure - namely the final rename. ...
    (microsoft.public.vc.mfc)
  • Re: How do I get a list of filenames with spaces on bash?
    ... in that case, mv doesn't affect the file not even its inode, it ... affects the current directory, it's just a rename. ... A failing cp may leave an ... Also note that cp may not preserve file attributes like ...
    (comp.unix.shell)
  • Re: How do I get a list of filenames with spaces on bash?
    ... To ensure that in the event of a failure the original file is unaffected. ... in that case, mv doesn't affect the file not even its inode, it ... affects the current directory, it's just a rename. ...
    (comp.unix.shell)
  • Re: trouble with msconfig.exe
    ... The original file has been renamed to msconfig.old (I don't know the ... msconfig.exe directly from Windows installation CD-Rom (it's Windows XP ... I can't rename or delete msconfig.old. ... Be sure the machine is clean first: ...
    (microsoft.public.windowsxp.general)
  • Re: Demotion DC
    ... but the second DC is failing (Hard Disk problems) so I will need ... You cannot even EASILY rename ... contents of the failing drive to new disk. ... Accelerated MCSE ...
    (microsoft.public.win2000.active_directory)