|
Aimed at power users and system administrators, this course explains the ins and
outs of the Bourne Again shell in a down-to-earth way. While you do need some
UNIX or Linux experience to get the most out of it, the book starts with an
in-depth discussion of the basic shell components and building blocks, such as
the UNIX commands, shell functions and parameters and how they are put together
using the shell syntax. Several ways of debugging are demonstrated, along with
hints and tips throughout the book that stimulate the reader to pay attention to
good programming practices in the fields of style, optimization and code recycling.
If you know how the shell operates and processes input, you're already half way
in understanding shell scripts. Thus a great deal of attention is spent on the
shell environment, initialization files, the declaration of variables, how the
quoting system works and how the shell expands expressions that you feed it.
According to UNIX professionals, you should know at least one text processing
language in order to work fast and - more or less - clean. In this spirit the
book discusses regular expressions, because these are used by many UNIX tools.
Then the reader has the choice between the sed streamline editor or the awk
reporting language, and preferably chooses both, of course. These two
processing languages have rather flat learning curves and allow for more
interesting, realistic and practical examples later in the course.
The first attempts at some real programming can now be started. Condition
testing is one of the first things that any program does, and a shell script
is no different: most scripts rely heavily on outcome of tests in order to
decide what to do next. While some consider users a necessary evil, the guide
tries to be friendly towards them and contains several tips to create
interactive scripts. Sometimes, however, input is needed while there is
nobody there to give it. Also this problem is tackled and demonstrated with
examples.
The whole purpose of a script is to make execution of repetitive tasks faster
and easier. You are not likely going to write a script for one-time
execution, and commands might have to be executed multiple times within the
steps necessary to perform a certain task. Consequently, there is a long
chapter about different types of loops, when to use which and how to
incorporate them in a smart way, again with lots of examples.
Since variables make up such an important part of shell scripts, there is an
entire chapter discussing different sorts at length. Read-only and array
variables are described and explained by example, and Bash features for
performing arithmetics and substitution on variables are reviewed.
All this comes together in functions, which are really pieces of re-usable code. The guide considers how function arguments and exit codes relate to the rest of the script and again presents the reader with plenty of examples.
And in the end, when things go wrong, you need to be able to stop a script,
which leads to a short discussion about signals and how to trap them. On the
other hand, traps might also be included in scripts in order to prevent them
from being interrupted, or for debugging purposes.
As usual with courses authored by Machtelt Garrels, this one also comes with exercises at
the end of each chapter that will test your preparedness for the next one and
that help assimilate the theory.
|