In UNIX there are many ways to accomplish the same task. Given a problem to solve,
we may be able to get to a solution in any number of ways. Of course, some techniques
will be more efficient, use fewer system resources, and may or may not give the user
feedback on what is going on or give more accurate details and more precision to the
result. In this book we are going to step through every detail of creating shell scripts
to solve real-world UNIX problems and tasks. The shell scripts range from using a
pseudo-random number generator to creating passwords using arrays to replicating
data with rsync to working with record files. The scope of solutions is broad and
detailed. The details required to write a good shell script include commenting each
step for future reference. Other details include combining many commands together
into a single command statement when desirable, separating commands on several
lines of code when readability and understanding the conceptmay be diminished, and
making a script readable and easy to maintain through the life cycle. We will see the
benefits of variables and files to store data, show methods to strip out unneeded data
from command output, and format data for a particular purpose. Additionally, we are
going to show how to write and use functions in our shell scripts and demonstrate the
benefits of functions over a shell script written without functions.
This book is intended for any flavor of UNIX, but it emphasizes the AIX, HP-UX,
Linux, OpenBSD, and Solaris operating systems.Almost every script in the book is also
included on the book’s companion web site (www.wiley.com/go/michael2e). Many
of the shell scripts are rewritten for various UNIX flavors, when it is necessary. Other
shell scripts are not platform-dependent. These script rewrites are necessary because
command syntax and output vary, sometimes in a major way, between UNIX flavors.
The variations are sometimes as small as extracting data out of a different column
or using a different command switch to get the same result, or they can be as major
as putting several commands together to accomplish the same task and get a similar
output or result on different flavors of UNIX.