Re: Spaces in file names



Hey, that works! Thanks.

"Dan Mills" <dmills@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:477856c3$0$21094$da0feed9@xxxxxxxxxxxxxxxxx
On Sun, 30 Dec 2007 19:31:45 -0600, Leslie Rhorer wrote:

OK, here's the problem. I need to automatically manipulate the file
names
of a number of files whose filenames have spaces in them.
for file in `ls -1 *`
do
<do stuff>
done

How about something like (untested):

#!/bin/bash
IFS=$'\n'

#IFS is the internal field separator in bash and
#here we set it to be new line only.

for file in $(find . -type f)
do
<stuff with "$file">
done

HTH.
Regards, Dan.


.



Relevant Pages

  • Re: Spaces in file names
    ... of a number of files whose filenames have spaces in them. ...
    (comp.os.linux.development.apps)
  • Re: Spaces in UNIX Filenames Bad
    ... >> because of the way bash treats space characters the solution wasn't ... > What if there are filenames which contain quotes? ... >> # get position of trailing double quote ... Enrique, Chris, thank you both for your thoughtful comments. ...
    (comp.os.linux.misc)
  • Re: One liner for count number of lines of files in a directory
    ... I don't know for bash, but for zsh, that would be: ... That doesn't include dot files. ... if you want to ommit symlinks to regular files. ... But note that the filenames won't be sorted and "./" will be ...
    (comp.unix.shell)
  • Re: Spaces in UNIX Filenames Bad
    ... > because of the way bash treats space characters the solution wasn't ... What if there are filenames which contain quotes? ... With bash (or any POSIX shell), ... > # get position of trailing double quote ...
    (comp.os.linux.misc)
  • Re: grep is always recursive
    ... $ grep "lala" * ... Is it a bash problem? ... bash expansion _must_ expand all globs. ... clearly coming before filenames. ...
    (Ubuntu)