2

Trying to do a mass convert from M4A to OGG in a large music collection, I have:

#!/bin/sh
for i in `find /home/family/Music -name *.m4a -print0`
   #do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac 2 "$i.ogg";
   do echo $i
done

All of the files will have spaces in their names, the output for the above shows a single file like this:

/home/family/Music/The
Kooks/Inside
In
_
Inside
Out/06
You
Don't
Love
Me.m4a

Every space marks a new line, I thought -print0 would fix this?

2

2 Answers 2

4

Use while loop together with read -d '' -r:

find /home/family/Music -name '*.m4a' -print0 | while read -d '' -r file; do
   echo "$file"
done
2

You can move the external loop into an "internal" loop and obviate word-splitting issues like so:

find /home/family/Music -name '*.m4a' -exec \
sh -c 'for i; do ffmpeg -i "$i" -acodec libvorbis -aq 6 -vn -ac 2 "$i.ogg"; done' sh {} +

Notice that -print0 is no longer needed Additionally, you need to quote *.m4a to avoid accidental glob expansion by shell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .