[lug] Shell Scripting Book

Tkil tkil at scrye.com
Sun Oct 14 00:24:09 MDT 2001


>>>>> "Kyle" == Kyle Moore <kmoore at mooreimages.com> writes:

Kyle> Anyone have a recommendation for a good shell scripting book? I
Kyle> am looking for something advanced...not basic stuff I already
Kyle> know.

the shell is, in many ways, just the "basic stuff"; anything more
advanced should probably be handled by tools (other programs), while
the shell just glues them together.

i find that dealing with complicated shell scripts is more painful
than just porting them over to, e.g., perl -- but then, i'm a perl
bigot.  mostly, i find it helpful to have a language with sane quoting
rules, reasonable string manipulations, and obvious arithmetic and
similar operations.  any other scripting language shares most, if not
all, of these attributes; so python, ruby, pike, and so on are all
reasonable choices as well.  perl has the "advantage" of being closest
to shell syntax, which might help the switch -- or it might not.  :)

(one of the problems with heavy shell scripting is that each tool has
it's own "mini-language", sometimes more than one: take a look at the
"sort" man page, for instance.  then there's awk...)

one can view "awk" as somewhere more powerful than shell but less so
than python, perl, etc.  the later revisions of awk (gawk, mawk,
nawk?) address some of the concerns, but perl (at least) was written
at least in part because Larry Wall found awk lacking.

using a sufficiently advanced shell might also do the trick; a recent
interview with David Korn (whence "the Korn shell") mentioned that
they briefly switched to using perl for some scripts around 1990 or
so, but that they found ksh93 could do everything they needed at the
time, so they got back to pure shell scripting.

here, "sufficiently advanced" probably means bash or ksh93+.  i fear
and loath csh, so i have no idea if zsh or any other csh descendant/
clone has caught up.  there's also "rc", the plan 9 shell, which is
supposed to be very neat -- but it's non-standard, so not very
attractive from a portability standpoint.

what kind of advanced things are you trying to do in the shell?  we
might be able to give more recommendations if we had a better idea of
where you were going with this.  also, take a look at the various
scripts used by the linux distribution you have at home: /etc usually
has lots of them (/etc/rc.d/rc.sysinit and friends, on redhat, is a
good place to start).  

simply reading the man and info pages on various shells can be
educational; i know the commercial ksh man page is huge, and covers a
lot of territory.  a bit of reading and lots of experimentation is
also helpful for learning the more esoteric corners of shell
programming (fancy redirections, trapping signals, etc)

look through the intro(1) man page.  it should cover most of the
"tools" that are most frequently used in shell scripts:  test, eval,
cut, paste, sort, nl, uniq, wc, pg, grep.  if it isn't maintained,
just look in /bin and /usr/bin ... see what's there.  :)

i'd guess that some of the classic unix books probably cover this area
as well, maybe "programming in the unix environment" or similar.  give
it a look at a library the next time you happen to be at one.

t.



More information about the LUG mailing list