Mike Meyer wrote: >> 2) run, before you run pdflatex, something like >> for FILE in `find . -name '*\.gif'`; do convert $FILE `echo $FILE | >> sed 's/\(.*\.\)gif/\1png/'`; done > > basename is safer: > > for file in $(find . -name *.gif) > do > convert $file $(basename $file .gif).png > done
Hi, Mike. Hi, Maarten. One step forward (basename) but one step backward too :P You need to quote the *.gif in the find expression: for file in $(find . -name '*.gif') or the shell will perform a glob expansion to those files ending with ".gif" in the current directory. One additional improvement: in general, you should always quote $file or nasty things will happen when the file name contains spaces. Unfortunately, the script above is fundamentally unable to handle files with spaces. To illustrate: $ mkdir foo $ touch 'foo/bar bar.gif' $ touch 'foo/baz baz.gif' $ for file in $(find foo -name '*.gif') do echo "$file" done foo/bar bar.gif foo/baz baz.gif $ find foo -name '*.gif' | while read file do echo "$file" done foo/bar bar.gif foo/baz baz.gif The second version doesn't suffer from buffer overflow problems either. In conclusion, I'd recommend that you use find foo -name '*.gif' | while read file do pngfile=`basename "$file" .gif`.png convert "$file" "pngfile" done (The command `...` is synonymous with $(...).) Ain't scripting a can of worms? :) Regards, Angus