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



On Thu, 24 Jan 2008 09:00:27 -0600, Ed Morton wrote:
[...]
for f in *\ *
do
n="${f// /_}"
[ ! -f "$n" ] &&

[ -f ... ] test whether the file exists *and* is a regular file
(or symlink to regular file). What if it exists and is a
directory?

cp -- "$f" "$n" &&
rm -- "$f"
done
[...]

Why not mv? cp won't work great for non-regular files.

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

--
Stephane
.



Relevant Pages

  • Re: negate if condition
    ... the file exists and is a regular file (or a symlink to a regular ... Note that it also returns false if you don't have the permission ... to "stat" that file (for instance if you don't have the search ... file that it points to if it's a symlink). ...
    (comp.unix.shell)
  • Re: a question about symbolic link
    ... > I would like to link to the regular file that 'X' ... to get the real path of a file, whether it is a symlink or a real file. ... Regards, ...
    (comp.unix.shell)
  • Re: Wanted: Example tar files
    ... On Tuesday 18 May 2004 03:57, Tim Kientzle wrote: ... > * regular file ... > * symlink to a file with a very long pathname ... How about posting such a tar somewhere so people can retar it with whatever ...
    (freebsd-hackers)
  • Re: I dont understand why this code isnt working
    ... >> separate test. ... > You might end up removing a voicecleanup.txt file that is not a ... test -f symlink will return true if the symlink refers to a regular file. ...
    (comp.unix.shell)
  • Re: Easier test for "regular file"?
    ... > I'm writing a package that needs to interact with cvs. ... > I want to do I need the ability to determine whether or not a file ... are you sure that a symlink to a regular file is unacceptable: ...
    (comp.lang.perl.misc)