Re: writing shell scripts



On Wednesday 18 March 2009 23:12, Lars Eighner (usenet@xxxxxxxxxxxxxxx)
opined:

In our last episode, <gpsitl$2t6g$1@xxxxxxxxxxxxxxxxxxxx>, the lovely and
talented Christopher Chambers broadcast on comp.unix.bsd.freebsd.misc:

Does anyone know a good referrence source that teachs you how to write
shell scripts?

I tried typing "man foreach" but it was no help.

Shirley man <name of shell> would be more likely to be informative.

--
Lars Eighner SAVE BEASTIE! "What do you do when you're
debranded?"
usenet@xxxxxxxxxxxxxxx
http://larseighner.com/
"Stale dependency": When pkgdb -F reports this, it means the dependency
is
missing, not that the dependency is obsolete.

Apart from the above advice, I'd ask what you have in mind for your
scripting. While it's possible to write multi-page scripts in the shell
of your choice - see portmaster in the ports collection for an excellent
example - the general rule of thumb is that shell scripts should be a page
of less in length. Anything more should be written in, e.g., perl or
python or an equivalent scripting language. This isn't hard and fast (and
isn't meant to set off a religious war!), but is something to keep in mind
as you approach the task you want to script.

As for specific books, look for "The KornShell Command and Programming
Languge", by Morris Bolsky and David Korn, Prentice-Hall, and "The UNIX C
Shell Field Guide", by Gail and Paul Anderson, also from P-H. I don't
know if either is still in print - my copies are 15-20 years old - but
both are much thumbed, excellent references to the specific shell
languages. You might be able to find them in a used book store or
on-line - worth a shot.

Bear in mind, too, that both ksh and bash are super-sets of the original
Bourne shell (sh), while csh/tcsh/zsh form a family of their own. Each
family has its own merits and demerits which you'll have to learn for
yourself. Another general rule of thumb - if you learn ksh or bash, you
will have learned the other variants; the same applies with csh/tcsh/zsh -
learn one and you've pretty well learned all of them. Yes, there ARE
differences and "improvements" in the later shells, but there is also a
high degree of consistency within the families.

Didn't mean to write a book or to set off WW-3 here. Hope this helps.

Scriptin' Ol' Bob

--
Robert G. Melson | Rio Grande MicroSolutions | El Paso, Texas
-----
A government big enough to give you everything you want is big
enough to take away everything you have. Thomas Jefferson
.



Relevant Pages

  • Re: Apparently, csh programming is considered harmful.
    ... Can someone please explain why bash sucks? ... boot scripts without bashisms. ... I don't understand why everyone insists on POSIX compliance for portability ... with shell scripting. ...
    (freebsd-questions)
  • Re: [Long] about ksh93 (Was: Bourne Shell Programming on Windows)
    ... Are you saying that David Korn is an unitiated or ignorant ksh ... > You provided one obscure example that does not occur in scripts. ... > in every shell. ... that should be teached in every shell programming book. ...
    (comp.unix.shell)
  • Re: Add user in Unix from command Line
    ... what shell the script should be interpreted with. ... Do you have any concept how many linux scripts that are part of the ... of relying on bash extensions are negligible. ... Those scripts at least in the sco case were probably a conscious design ...
    (comp.unix.sco.misc)
  • Re: conversion of csh scripts to bash
    ... > I recognize that bash is the superior shell, but like many people, I was ... > first exposed to csh 12 years ago because that's what everyone in my ... Note that shell programming sucks in general, ... I would certainly not write bash specific scripts, but instead, ...
    (comp.unix.shell)
  • Re: question about Dash
    ... bash isn't - well it has whats called bash-isms ... Both are POSIX compliant as far as I can tell. ... so it cannot run scripts using them. ... shell on many UNIXes, and sometimes was even used as /bin/sh. ...
    (Debian-User)