Re: How do I get a list of filenames with spaces on bash?
- From: Stephane Chazelas <stephane_chazelas@xxxxxxxx>
- Date: 24 Jan 2008 17:38:26 GMT
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
.
- Follow-Ups:
- References:
- Re: How do I get a list of filenames with spaces on bash?
- From: jellybean stonerfish
- Re: How do I get a list of filenames with spaces on bash?
- From: Chad
- Re: How do I get a list of filenames with spaces on bash?
- From: Ed Morton
- Re: How do I get a list of filenames with spaces on bash?
- From: Stephane Chazelas
- Re: How do I get a list of filenames with spaces on bash?
- From: Ed Morton
- Re: How do I get a list of filenames with spaces on bash?
- Prev by Date: Re: How do I get a list of filenames with spaces on bash?
- Next by Date: Extract block of text
- Previous by thread: Re: How do I get a list of filenames with spaces on bash?
- Next by thread: Re: How do I get a list of filenames with spaces on bash?
- Index(es):
Relevant Pages
|