Re: Spaces in file names



"Leslie Rhorer" <lrhorer@xxxxxxxxxxx> wrote:
Hey, that works! Thanks.

But it would be a lot easier to just do this:

#!/bin/bash

for file in * ; do
echo "$file"
done
exit 0

The trick is putting quotes around $file. Using `ls -1 *`
is unnecessary, and so is find.


"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.

--
Floyd L. Davidson <http://www.apaflo.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) floyd@xxxxxxxxxx
.



Relevant Pages

  • Re: Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • Newbie Three
    ... echo "tesgform"; ... echo "suspected alien invasion case topic table"; ... echo "suspected alien invasion unknown group name"; ...
    (comp.lang.php)
  • ToDo list utility - suggestions/optimizations/refinements wanted
    ... For the past couple of days, I've been working on this todo list script and I'm really happy with the way it works, but wanted to post it here before I go any futher, in case anybody had suggestions for optimizations or style errors. ... echo "File written successfully." ...
    (comp.unix.shell)
  • Re: Shell Script to Remove Old Files
    ... Note it needs a TSM server: ... # Verify command line arguments ... echo "\nError: $STARTDIR does not exist.\n" ...
    (comp.unix.admin)
  • Re: Making bootable USB keys
    ... mv $TMPDOC $TMPDOC.old ... echo -n " initializing partition table " ... echo "convert tree $tree image $imagefile" ...
    (freebsd-hackers)