Mailing List Archive


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

Re: [tlug] Batch conversion of a bunch of Illustrator files to SVG files



On 2009-08-05 21:29 +0900 (Wed), Stephen J. Turnbull wrote:

>  > #!/bin/bash
>  > for i in `find -name '*.ai'`; do
>  >     uniconverter input ${i} output ${i%.ai}.svg
>  > done
> ...
> jep points out the possibility of names with spaces (or even more evil
> things) in them.  I *think* that putting double (not single!) quotes
> around the variable references will handle that case, eg, "${i}".

Unfortunately for this case, no, it will not; the backquoted portion is
replaced by the entire output of find, and only then is field splitting
performed according to the contents of $IFS:

    $ touch _a "_b c" _d
    $ for i in $(find . -maxdepth 1 -name _\*); do echo $i; done
    ./_a
    ./_d
    ./_b
    c

Note that this isn't a problem for shell globs:

    $ for i in _*; do echo $i; done
    _a
    _b c
    _d

If you really want to deal with funny filenames, even those with
newlines in them, I believe that your best bet is to use a script that
takes the filename as a parameter, use -print0 with find, and use xargs
to invoke the script:

    $ cat > doit <<__EOF__
    uniconverter input "$1" output "${1%.ai}.svg"
    __EOF__
    $ find . -maxdepth 1 -name _\* -print0 | xargs -0 doit

> Shell quoting is very hard to get correct....

I would consider myself an rather experienced shell scripter, and
even more me quoting stuff truly properly is very hard to get right.
Generally, I no longer bother to try to get it right for all cases, as
it also happens to reduce readability.

If you don't know shell, I'd probably recommend just learning Ruby or
Python or something like that instead, and using that for your scripting
needs.

cjs
-- 
Curt Sampson       <cjs@example.com>        +81 90 7737 2974
           Functional programming in all senses of the word:
                   http://www.starling-software.com


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links