eps to jpg conversion - which program?

Jeremy Chadwick koitsu at FreeBSD.org
Sat Nov 8 23:36:35 PST 2008

On Sun, Nov 09, 2008 at 07:25:49AM +0100, Polytropon wrote:
> On Sat, 8 Nov 2008 12:12:46 +0200, Jonathan McKeown <jonathan+freebsd-questions at hst.org.za> wrote:
> > Essentially, a Bourne-type shell with parameter expansion expands 
> > ${variable#prefix} or ${variable%suffix} to $variable with the prefix or 
> > suffix, respectively, removed.
> So this would be more efficient:
> 	#!/bin/sh
> 	for f in *eps; do
> 		[ ! -f ${f%.eps}.jpg ] && convert $f ${f%.eps}.jpg
> 	done


Also, what guarantee do you have that all the filenames that match that
wildcard lack spaces in them?  Your [ and convert commands will botch
badly in that case.  See below.

What people often forget while writing sh scripts is that spawning
external utilities slows down the script greatly, and destroys system
resources.  You might think "My machine has 923484390GB of RAM, and has
6500 processors; why do I care?" -- step back for a moment and think
about older/smaller boxes, or even more importantly, embedded machines
(very little memory, very little CPU).

Also think about situations where fork() will fail due to resource
limits or existing system resource exhaustion; what then?  I see this
regularly in perl scripts; people relying on `xxx` for no good reason.
I ask them, "Why are you doing this?  Can you not use <native-perl-code>
instead, and avoid wasting resources and excessive risk?", and they
often have no idea what I'm talking about.  And whenever I see `ssh
user at host "command"` in perl scripts, I cry.

That in mind, don't let your scripting mimic that of "perl bastards" who
*intentionally* write obfuscated code just to "show off" (often citing
"its faster" as the reason, choosing to intentionally ignore that perl
is a compiled language).  For complex pieces of sh that are hard to
visually parse: try to keep it simple, and take the time to write
decent/legible comments above the hairy part of the script.

Also remember that double-quoting filenames or variables that are used
as filenames is a VERY good idea.  Filenames with spaces are quite
common these days.  It's best to assume the worst, but not be *too*

And don't forget about "set noglob" when appropriate!

| Jeremy Chadwick                                jdc at parodius.com |
| Parodius Networking                       http://www.parodius.com/ |
| UNIX Systems Administrator                  Mountain View, CA, USA |
| Making life hard for others since 1977.              PGP: 4BD6C0CB |

More information about the freebsd-questions mailing list