[buug] Spaces within filenames in a bash script

Joseph Zitt jzitt at josephzitt.com
Sun Jan 1 22:12:33 PST 2006

Hi, all. This would seem to be an FAQ, but I haven't been quite able to 
get it to work after a lot of experimenting and digging around.

I'm using a bash script that I got from an article on an O'Reilly site 
to convert FLAC files to mp3s. (I'm guessing that it could easily be 
tweaked to do oggs, but the problem would be the same.) It's blowing up 
badly on files with spaces in the names:

FILES=$(ls *.flac | cut -d '.' -f1)
for i in $FILES; do
         echo converting: $i.flac
         flac -sdc $i.flac | lame - $i.mp3

I've tried all sorts of different incantations, mostly throwing 
quotation marks in to see what would work, but no matter what I do, it 
takes a filename like "foo bar baz.flac" and treats it as three files, 
"foo", "bar", and "baz.flac".

Can someone suggest a tweak that will handle this (other than renaming 
the files to start with, which would be even more of a hassle)?

Thanks for any enlightenment.

More information about the buug mailing list