PDA

Xem tài liệu đầy đủ : Tài Liệu Mastering UNIX Shell Scripting



Cruz_Pham
08-06-2011, 10:40
In Unix there are many ways to accomplish a given task. Given a problem to solve, we
may be able to get to a solution in any number of ways. Of course, some will be more
efficient, be more readable, use less disk space or memory, 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 writing a shell script to
solve real-world Unix problems and tasks. The shell scripts range from using a pseudorandom
number generator to create pseudo-random passwords to checking for full
filesystems on Unix machines and to sending pop-up messages to Windows desktops.
The details required to write these shell scripts include using good style and providing
good comments throughout the shell script by describing each step. Other details include
combining many commands into just one command statement when desirable, separating
commands on several lines when readability and understanding of the concept may
be diminished, and making a script readable and easy to maintain. We will see the benefit
of using variables and files to store data, show methods to strip out unwanted or
unneeded data from a command output, and format the data for a particular use. Additionally,
we are going to show how to write and include 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 its emphasis includes AIX, Linux,
HP-UX, and Solaris operating systems. Most every script in the book is also included on
the book’s companion Web site (www.wiley.com/compbooks/michael). Many of the shell
scripts are rewritten for each different operating system, when it is necessary. Other shell
scripts are not platform dependent. These script rewrites are sometimes needed because
command syntax and output vary, sometimes in a major way, between Unix flavors. The
variations are sometimes as small as pulling the data out of a different column or using a
different command switch, or they can be as major as putting several commands together
to accomplish the same task to get similar output or result on different flavors of Unix.
In each chapter we start with the very basic concepts and work our way up to some
very complex and difficult concepts. The primary purpose of a shell script is automating
repetitive and complex functions.