[lug] Shell Scripting Help

Dan Ferris dan at usrsbin.com
Tue Feb 14 12:45:02 MST 2006


Ok, using read worked perfectly fine.  Thanks a lot.

Even exporting IFS didn't work.  You learn something new every day.

Dan

Zan Lynx wrote:
> 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.
>>>       
>>> ------------------------------------------------------------------------
>>>
>>> _______________________________________________
>>> Web Page:  http://lug.boulder.co.us
>>> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
>>> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug

-- 
Chuck Norris doesn't sleep.  He waits.




More information about the LUG mailing list