[buug] Spaces within filenames in a bash script
brian at dessent.net
Mon Jan 2 02:00:09 PST 2006
Joseph Zitt wrote:
> FILES=$(ls *.flac | cut -d '.' -f1)
> for i in $FILES; do
> echo converting: $i.flac
> flac -sdc $i.flac | lame - $i.mp3
You should consider using find instead of ls. And it looks like what
you have would die if you had a filename with more than one "." in it.
find . -name \*.flac | while read F; do
echo "converting: $F"
flac -sdc "$F" | lame - "$(basename "$F" .flac).mp3"
By the way, just for simple commands the best way to do this is:
find /path -name \*.whatever -print0 | xargs -0 command
...which will handle filenames with spaces, quotes, tabs, newlines, and
More information about the buug