Looking For Tutorial Comparison Of sh - perl - python

Dan Stromberg drsalists at gmail.com
Sun Nov 14 17:31:48 EST 2010


On Sun, Nov 14, 2010 at 5:00 AM, Martin Gregorie
<martin at address-in-sig.invalid> wrote:

> On Sat, 13 Nov 2010 22:05:57 -0600, Tim Daneliuk wrote:
>
> > I am putting together a comparison & intro to each of sh, perl, python
> > with a view towards addressing:
> >
> Add awk / gawk to that list. IME its often the easiest and most concise
> way to process a text file, e.g. a log file, while applying different
> processing rules depending on line content and/or generating summaries.
>
> > Before I attack this myself, has anyone done
> > something along these lines I could piggyback upon?
> >
> I haven't seen such a comparison, but that doesn't meant that they don't
> exist.
>

The perl people might not agree (they seem to frown on the idea of exec'ing
anything external, at least when you do it from shell), but I see
sh/ksh/bash programming as Including awk, sed, tr and grep, among other
tools - and I see that as a Good Thing (tm).  As I see it, this keeps POSIX
shell proper quite a bit leaner, and very interestingly, makes it very
naturally parallelisable.

Another cool thing about POSIX shell programming, is that with shell
functions, you can have internal extensions (shell functions) and external
extensions (shell scripts), with exactly the same syntax in the way they are
called, and almost exactly the same syntax in the way they are defined; it
almost doesn't matter in which way something was implemented (until you
involve subshells).

POSIX shell does have its issues though - mostly the proliferation of #!$%
noise in the builtins.

I hope you'll include something about the fact that POSIX shell is white
space sensitive - albeit in a different way from Python.

Oh, also, the perl people tend to want to slam POSIX shell for not being
portable; I think it is, really, you just need a small amount of information
about how to do it.  The usual example that gets trotted out is that to
suppress a newline you have to say "echo -n fred" in BSD-ish shells, and
"echo 'fred\c'" in SysV-ish shells - but:
1) Almost all sh/ksh/bash implementations do -n now.
2) Even if that weren't the case, you could always portably say "echo fred |
tr -d '\012'".

HTH
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101114/2e04cec6/attachment-0001.html>


More information about the Python-list mailing list