[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: bash vs. python scripts - which one is better?

On Tue, Aug 07, 2007 at 04:23:28PM -0700, David Brodbeck wrote:
> To do this with find, I'd try something like this:
> find . -name "*.wav" -exec lame -h -b 160 \{\} \{\}.mp3 \;
> It's possible spaces will bite you here, too ... If you actually attempt 
> this on filenames with spaces, test it first and see if you need to add 
> another level of quoting.  Note that you have to escape the curly brackets 
> and the semicolon so find sees them, instead of bash trying to interpret 
> them.  Find's syntax for the "exec" action is kind of awkward-looking, but 
> ...

A minor point, but I use find a lot and never see the need to escape the
curly brackets under bash. I suppose this may take (mis)advantage of the
following statement in bash(1), under Brace Expansion:

       A  correctly-formed  brace  expansion must contain unquoted opening and
       closing braces, and at least one unquoted comma  or  a  valid  sequence
       expression.   Any incorrectly formed brace expansion is left unchanged.
       A { or , may be quoted with a backslash to prevent its being considered
       part  of  a brace expression.  To avoid conflicts with parameter expan-
       sion, the string ${ is not considered eligible for brace expansion.

So, for what it's worth, I'd write the above as:

    find . -name \*.wav -exec lame -h -b 160 {} {}.mp3 \;

> Note that find -exec can also do a lot of damage in a hurry.  If you're 
> doing anything remotely destructive, you might want to substitute "echo 
> \{\}" for your command the first time you run it, just to make sure find is 
> only finding the stuff you want it to!   Also, before you start thinking of 

Good advice, but I often do this even for non-destructive commands, just to
make sure what's going to happen. You really only need to insert 'echo' in
front of the command, and will see the expanded command in the output. E.g.,
the previous command would be:

    find . -name \*.wav -exec echo lame -h -b 160 {} {}.mp3 \;

If it looks good remove the 'echo', or maybe pipe the resulting list of 
commands into xargs.


Ken Irving, fnkci@uaf.edu

Reply to: