[lug] Shell Scripting Help

Zan Lynx zlynx at acm.org
Tue Feb 14 12:32:09 MST 2006


No need to export IFS, it is only important to the shell itself.  No
external program needs to see it.

However, I have another suggestion that I like better. :)

Try it this way:
find . -name "*.m4a" | 
while read i; do ffmpeg -i "$i" -acodec mp3 -ac 2 -ab 192 "${i%m4a}mp3"; done &&
find . -name "*.m4a" -print0 | xargs -0 rm -f

"while read i" will read complete lines into $i so no need to mess with
IFS.

I like find -print0 and xargs -0 better because otherwise, if you have
more files than whatever the max command-line size is (32K?), it'll
fail.  xargs automatically splits the commands up into max command-line
sized chunks.  The find | while read has the same benefit of handling
any sized stream of filenames.

Warning: I didn't test this scriptlet, so your own risk, etc.

On Tue, 2006-02-14 at 12:13 -0700, Bamm Visscher wrote:
> The for loop treats the space as a seperator. Do something like
> `export IFS=;` and run your one liner again. As long as you don't have
> any semi colons in your filenames, it should work fine.
> 
> Bammkkkk
> 
> 
> On 2/14/06, Dan Ferris <dan at usrsbin.com> wrote:
> > So, I came into a bunch of MP4 formatted music files from my younger
> > brother and naturally, I'd like to convert them to MP3 since dealing
> > with MP3s is way easier in the long run at least for me. These aren't
> > iTunes encrypted MP4s either, so there is nothing to crack or decrypt,
> > just straight conversion.
> >
> > So being the geek that I am, I had my hopes of making a very simple
> > shell script that would go through and convert all the m4a files using
> > ffmpeg. Sounds simple right?
> >
> > So it seems obvious that one could do something like this:
> >
> > for i in `find . -name "*.m4a"`; do ffmpeg -i "$i" -acodec mp3 -ac 2 -ab
> > 192 "${i%m4a}mp3"; done && find . -name "*.m4a" -exec rm -f \{\} \;
> >
> > A one line converter that will run for a few hours and give me the MP3
> > files that I so desperately seek and rid my hard disk of the pesky MP4
> > files.
> >
> > However, there is one little caveat and it's driving me INSANE and I'm
> > ready to start throwing things.
> >
> > find will return a file such as this:
> >
> > ./AC_DC/The Razors Edge/01 Thunderstruck.m4a
> >
> > However, when you try to actually USE this file name in a script it
> > shows up like this:
> >
> > ./AC_DC/The
> > Razors
> > Edge/01
> > Thunderstruck.m4a
> >
> > None of the other commands show strange characters in the file name.
> > I've tried to rid the output of funny characters with perl but nothing
> > makes it go away.
-- 
Zan Lynx <zlynx at acm.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20060214/61bee9c1/attachment.pgp>


More information about the LUG mailing list