On Sat, 8 Nov 2008 23:36:32 -0800, Jeremy Chadwick <[EMAIL PROTECTED]> wrote:
> 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.

This is completely correct. If files are present as foo.EPS,
the "Windows" style of file naming, or foo.Eps in a mixed form,
the *.eps wouldn't catch it.

As you mentioned, it's good to assume the worst case. Not only
spaces, as well special characters. Now *that's* the real fun. :-)

        [EMAIL PROTECTED] sent me | Copy [5] of C:\My Files\A&V with ö and ß.Eps

Another mentionable comment would be: "Why do you call the variable
just $f? Give it a better descriptive name." In this small example,
it won't lead into significant problems if you don't do it, but I've
seen shellscripts using $f, $f1, $f2, $g, $h, $y all over the file,
and it was hard to find out which values they should hold.



> <style-rant>
> 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).

Hey, that's how software development helps hardware development,
or at least software development in Redmond. :-)

                              Hardware ressources   ++
        Overall usage speed = ------------------------ = const.
                              Software requirements ++

q.e.d.


> 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
> [EMAIL PROTECTED] "command"` in perl scripts, I cry.

Ooow! Is this for real? If it is, it's a reason to hit someone's
head with the keyboard. :-)



> 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.

Indentation, comments and descriptive identifiers help a lot.
If you read FreeBSD's (scripting) sources, you'll see that they
are of high quality.



> 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.

Especially when you're intending to use a piece of software,
even if it's just a three line shell script, more than just one
time, or if you want to share it with others.




-- 
Polytropon
>From Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
_______________________________________________
freebsd-questions@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to