[X-Unix] shell scripting

Albert Lunde atlunde at panix.com
Sat Jan 17 05:12:39 PST 2004


On Sat, Jan 17, 2004 at 12:41:23PM +0000, David Ledger wrote:
> >On Jan 15, 2004, at 9:06 PM, Albert Lunde or  Bert Knabe (I lost track) 
> >wrote:
> >> perl makes a better Unix scripting toolbox that shell scripts or C++.
> For many things it does.  For file and directory manipulation a shell 
> and standard Unix utils is usually a lot easier.  You *can* do it all 
> in perl, but in shell, cp, mv, ditto etc are written just as you 
> would type them; in perl they have to be wrapped in a call (which may 
> be just ``) or actually coded up as perl routines.

The reason I would prefer perl, even for that kind of thing, is that
perl has clearer quoting conventions than the shells, and more
sanity checks available to catch errors. ("-w" and "use strict"
being first among them.)

If you call system or exec with an array containg the command
path and arguments of a command, you can completely avoid
using shell argument parsing, and thus be able to build
commands containing spaces and many special characters
in relative safely (one still has to worry about option
parsing by the command being run).

A perl script to do a given task may be longer, the way I write,
but it is probably more robost and reliable than a similar shell
script.  I know enough Bourn, Korn, and C shell scripting
to do fairly complicated things, I just don't want to
force myself to deal with all their quirks. Perl has less
type safely, than say Java or C++, but it's ahead of the Unix
shells and other OS's scripting languages like Rexx and DCL
that I've had to use in the past. Perl does have some novel
features, but the common syntax inherited from C will
help anyone with a background in other C-family languages,
and the camel book provides pretty explict documentation.



More information about the X-Unix mailing list