bash_spaces_in_filenames

This is part of The Pile, a partial archive of some open source mailing lists and newsgroups.



Subject: bash script question (for loops)
From: Mark Ivey <mbivey@puc.edu>
Date: Sat, 25 Nov 2000 22:34:11 -0800 (PST)

Ok, I have some directories with spaces in the names:
   $ ls -1
   Astral Projection/
   Divinorum/
   Fusion 19/
   GoaArchive/
   Starfire Records/

And I'm trying to write a bash script to modify files in each directory.
The spaces are giving me problems.  Here are two short bash scripts:
   LIST=*;      echo $LIST;
   LIST=$(\ls); echo $LIST;

Now, they both _seem_ to give the same output.  It looks like this:
   Astral Projection Divinorum Fusion 19 GoaArchive Starfire Records

Here are two more scripts, similar to the first 2:
   LIST=*;      for NAME in $LIST; do echo "-->" $NAME; done
   LIST=$(\ls); for NAME in $LIST; do echo "-->" $NAME; done

They give different output.  The first one gives:
   --> Astral Projection
   --> Divinorum
   --> Fusion 19
   --> GoaArchive
   --> Starfire Records

and the second one gives:
   --> Astral
   --> Projection
   --> Divinorum
   --> Fusion
   --> 19
   --> GoaArchive
   --> Starfire
   --> Records


So, how do I get the second one to work like the first one?  I've tried
putting quotes around the filenames (\ls -Q), but it doesn't work.  It
still splits the names at the spaces.  I will have other files alongside
the directories later, so I can't just use the * version. Also, I know I
could use the -exec flag on the find command, but I am having this problem
with a few other for loops that I can't use find on, so I would really
like to know how to get the for command to work.  Thanks....

===



the rest of The Pile (a partial mailing list archive)

doom@kzsu.stanford.edu