From owner-freebsd-questions@FreeBSD.ORG Sun Nov 9 07:36:35 2008 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 78C31106567D for ; Sun, 9 Nov 2008 07:36:35 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from QMTA01.westchester.pa.mail.comcast.net (qmta01.westchester.pa.mail.comcast.net [76.96.62.16]) by mx1.freebsd.org (Postfix) with ESMTP id 21FA98FC12 for ; Sun, 9 Nov 2008 07:36:34 +0000 (UTC) (envelope-from jdc@koitsu.dyndns.org) Received: from OMTA05.westchester.pa.mail.comcast.net ([76.96.62.43]) by QMTA01.westchester.pa.mail.comcast.net with comcast id cvca1a0010vyq2s51vcaCV; Sun, 09 Nov 2008 07:36:34 +0000 Received: from koitsu.dyndns.org ([69.181.141.110]) by OMTA05.westchester.pa.mail.comcast.net with comcast id cvcY1a0032P6wsM3RvcYGu; Sun, 09 Nov 2008 07:36:34 +0000 X-Authority-Analysis: v=1.0 c=1 a=oO8d8O7oX9UA:10 a=Zk91umX7DRkA:10 a=QycZ5dHgAAAA:8 a=BFsm0CsEZ8nkFt3g8oIA:9 a=om7tmLDYIkOsMk8rnw4A:7 a=ebcvHdNL0bPTWGZK7Wl_U8-9MnUA:4 a=EoioJ0NPDVgA:10 a=LY0hPdMaydYA:10 Received: by icarus.home.lan (Postfix, from userid 1000) id 3BA8F5C19; Sat, 8 Nov 2008 23:36:32 -0800 (PST) Date: Sat, 8 Nov 2008 23:36:32 -0800 From: Jeremy Chadwick To: Polytropon Message-ID: <20081109073632.GA32503@icarus.home.lan> References: <49143663.9070804@shopzeus.com> <20081107201954.5d7e4993.freebsd@edvax.de> <200811081212.46286.jonathan+freebsd-questions@hst.org.za> <20081109072549.7272df20.freebsd@edvax.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20081109072549.7272df20.freebsd@edvax.de> User-Agent: Mutt/1.5.18 (2008-05-17) Cc: freebsd-questions@freebsd.org, Jonathan McKeown Subject: Re: eps to jpg conversion - which program? X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 09 Nov 2008 07:36:35 -0000 On Sun, Nov 09, 2008 at 07:25:49AM +0100, Polytropon wrote: > On Sat, 8 Nov 2008 12:12:46 +0200, Jonathan McKeown 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 Significantly. 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 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@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* over-zealous. 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 |