Buy New

or
Sign in to turn on 1-Click ordering.
or
Amazon Prime Free Trial required. Sign up when you check out. Learn More
Buy Used
Used - Acceptable See details
$12.56 & eligible for FREE Super Saver Shipping on orders over $25. Details

or
Sign in to turn on 1-Click ordering.
 
   
Sell Back Your Copy
For a $0.43 Gift Card
Trade in
More Buying Choices
Have one to sell? Sell yours here
Portable Shell Programming: An Extensive Collection of Bourne Shell Examples
 
See larger image
 
Tell the Publisher!
I'd like to read this book on Kindle

Don't have a Kindle? Get your Kindle here, or download a FREE Kindle Reading App.

Portable Shell Programming: An Extensive Collection of Bourne Shell Examples [Paperback]

Bruce Blinn (Author)
4.6 out of 5 stars  See all reviews (26 customer reviews)

List Price: $56.60
Price: $43.73 & this item ships for FREE with Super Saver Shipping. Details
You Save: $12.87 (23%)
  Special Offers Available
o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o
In Stock.
Ships from and sold by Amazon.com. Gift-wrap available.
Only 3 left in stock--order soon (more on the way).
Want it delivered Monday, January 30? Choose One-Day Shipping at checkout. Details
Textbook Student FREE Two-Day Shipping for Students. Learn more


Book Description

0134514947 978-0134514949 October 29, 1995 1

Traditionally, books on shell programming present the shell as the user interface to UNIX. This complete guide shows how to use the shell to develop shell scripts, using the shell more like a programming language than a command interpreter. Covers shell syntax, portability on different UNIX systems, using shell scripts to catch or ignore signals, executing commands using the remote shell command, and using the shell's redirection syntaxes. For software development engineers, system administrators, and QA test engineers who work with UNIX computer systems.


Special Offers and Product Promotions

  • Buy $50 in qualifying physical textbooks, get $5 in Amazon MP3 Credit. Here's how (restrictions apply)

Frequently Bought Together

Customers buy this book with sed & awk (2nd Edition) $23.19

Portable Shell Programming: An Extensive Collection of Bourne Shell Examples + sed & awk (2nd Edition)
  • This item: Portable Shell Programming: An Extensive Collection of Bourne Shell Examples

    In Stock.
    Ships from and sold by Amazon.com.
    This item ships for FREE with Super Saver Shipping. Details

  • sed & awk (2nd Edition)

    In Stock.
    Ships from and sold by Amazon.com.
    Eligible for FREE Super Saver Shipping on orders over $25. Details



Editorial Reviews

From the Publisher

This complete guide shows how to use the shell to develop shell scripts, using the shell more like a programming language than a command interpreter. Covers shell syntax, portability on different UNIX systems, using shell scripts to catch or ignore signals, executing commands using the remote shell command, and using the shell's redirection syntaxes.

From the Inside Flap

The most frequently asked question in shell programming is:

Where can I find examples of shell scripts?

Most engineers find that the easiest way to learn shell programming is to learn from the examples of others. Similarly, the easiest way to write a shell script is to use an existing shell script as a template. This stems from the fact that there are innumerable commands and techniques that can be used to solve any particular problem. Seeing an example helps you sift through the chaff to get to a solution quickly. Oftentimes shell programming is used to solve a short-term problem, and, therefore, it is important to get something working quickly; the task might not be worth doing if it requires a significant amount of learning or trial and error to come up with a solution.

Seeing examples also helps you to remember the peculiarities of the shell syntax and the idiosyncrasies of the UNIX commands. Since writing shell scripts is not an everyday task for most engineers, it is easy to forget those infrequently used details. It is usually easier to modify a shell script that contains many of the ideas that you need than it is to develop a new shell script from scratch.

Shell programming is too useful to avoid simply because you find the syntax difficult to remember or the number of UNIX commands overwhelming. Besides executing simple commands such as echo, date, cp, and so forth, the shell defines a command language e that allows you to combine commands into complex shell scripts. The shell supports variables, control flow statements (such as if, while, and for), functions, parameter passing, and even interrupt handling. Coupling the capabilities of the shell with the wide variety of commands available on UNIX, very powerful shell scripts can be written in just a few lines. In addition, since the shell is an interpretive language, there is no compiling or linking to worry about. You can create simple and powerful shell scripts in just a few minutes.

When I first began to write shell scripts, I found it difficult to find useful examples of shell scripts, and when I did find them, they were often difficult to understand. To this end, I believe it is useful to have a reference of relevant, well-doc umented examples, which is what I have tried to provide in this book. I have also tried to provide enough variety in the examples and their explanations that you will become familiar with many of the common practices used in writing shell scripts, an d, therefore, it will be easier for you to understand the code in other shell scripts that you find. This is not a book on how to use UNIX, as most books on shell programming are. This book is intended for people who are already familiar with UNIX and, for one reason or another, have decided to write a shell script. This book is intended for people who already know what an if statement is, but they do not know or cannot remember how an if statement is implemented in the shell. If they could just see an example, they would be off and programming. The examples in this book cover everything from simple shell statements to complex shell scripts, and unlike most books on shell programming, this book contains examples that you are likely to use.

This book is intended to be useful as a reference book. The style of presentation is straightforward. Each topic is self-contained, which allows you to skip directly to the information that you are interested in. This book provides an extensive collection of examples that are organized and indexed so that you have a ready reference to a wide variety of shell programming tasks. If you choose to read the book from cover to cover, you will be exposed to a variety of techniques and practices that would normally take you years to discover.

All of the examples in the book are written using the standard Bourne shell1 (sh or /bin/sh), which allows these examples to be used on any UNIX system. While there are several shells to choose from on most UNIX systems, and many of them are more suitable table than the Bourne shell for interactive work, the standard Bourne shell is available on all modern UNIX systems, and therefore, is the most common choice for writing shell scripts. In addition, the Korn shell and the POSIX shell contain all of the e syntactic constructs of the Bourne shell, which makes the examples in this book compatible with those shells as well. Some of the examples in this book have dependencies on the flavor of UNIX (e.g., System V or BSD) and some of the examples are dependent upon the particular implementation of a command by the vendor, but these dependencies are explained in the text, and in each case a portable solution is shown. This makes the examples in this book especially useful to those who write shell scripts that must execute on more than one type of UNIX system.

When reading this book, it is important to remember that there are many ways to perform most tasks on UNIX systems. I have chosen implementations for the examples in this book that are easy to understand, but not necessarily the most efficient solution on, or in some other way, the most desirable solution. I will sometimes comment on alternatives, but for the most part, I leave it up to you to determine when an example from this book should be altered for your particular situation.

There is no warranty of any kind on the examples in this book. I have tested each example on several different UNIX systems, but because of the wide variety of UNIX systems and configurations available, it is possible that some examples will not work exactly as I have indicated. I welcome any comments that you might have about the content of this book, including problems with examples and suggestions for improvements.

How This Book Is Organized

The first four chapters in this book describe the syntax of the Bourne shell.

Chapter 1, "Shell Syntax," begins by introducing you to the basic syntax of the Bourne shell. This chapter describes simple commands, quotes and quoting, file name expansion n, and control flow statements.

Chapter 2, Shell Variables, continues the presentation of shell syntax. It describes how to assign values to variables, how to retrieve those values, variable initialization techniques, and variables that are built into the shell.

Chapter 3, Shell Functions and Built-in Commands, presents the syntax for shell functions and discusses techniques for using them. This chapter also lists the commands that are built into the shell and gives a brief description of each one.

Chapter 4, Using Files, presents the shell syntax for input-output redirect. It shows a variety of examples that use the shell redirection syntax to redirect the standard input and the standard output of commands, and it also discusses how to use the shell redirection syntax to read and write other files.

Chapter 5, The Environment, describes the process environment and how it affects shell scripts. This chapter discusses how parent and child processes can affect each other, how signals can be used in shell scripts, and it presents a variety of examples on how to execute commands on remote systems.

Chapter 6, Parsing Command Line Parameters, explains the conventions used to pass parameters to shell scripts and presents examples of common techniques that are used to parse the command line parameters.

Chapter 7, Using Filters, explains what a filter is, how to write one, and how they are used. This chapter contains many examples of filters that can be used to process text files.

Chapter 8, Shell Utilities, has examples of how to perform many common tasks that are frequently used in larger shell scripts. This chapter covers such things as doing arithmetic, manipulating strings, manipulating files and directories, asking questions, presenting output, and much more.

Chapter 9, Examples of Shell Functions, has examples of complete shell functions. These functions demonstrate a variety of reasons to use shell functions, and each function in this chapter contains a line-by- line explanation describing exactly how the function works.

Chapter 10, Examples of Shell Scripts, has examples of complete shell scripts. Each example is complete with comments and demonstrates good shell programming practices. Each shell script in this chapter contains a line-by-line explanation describing exactly how the shell script works

Chapter 11, Debugging, describes the debugging options in the shell and other techniques that are useful for debugging shell scripts. This chapter also describes a variety of common problems and unusual coding styles that can lead to errors.

Chapter 12, Portability, explains the most common issues surrounding the portability of shell scripts and how to avoid portability problems. This chapter also discusses some of the portability issues that arise with specific UNIX commands.

Chapter 13, Common Questions and Problems, is structured as a question and answer discussion. It explains many of the problems that inexperienced users are likely to encounter, and it answers many of the questions they are likely to ask.

Appendix A, Comparison of UNIX Shells, provides a brief description of each of the major shells available on UNIX systems

Appendix B, Syntax Summary, is a complete but brief summary of the syntax of the Bourne shell.

Conventions Used in this Book

To differentiate the text of the explanations in this book from the examples of shell code, typewriter font is used to represent the examples of shell code. Typewriter font is also used to indicate command names, file names, or anything else that must t be entered literally as it is shown in the text.

echo Hello world.

Text in italics is used to indicate text that should be replaced with an appropriate value rather than entering the text literally as it is shown.

rm file
When expressing command syntax, square brackets () indicate an optional entry, a vertical bar () separates multiple selections, and ellipses (...) indicate that the previous entry may be repeated.

cp file1 file2 ... target
Nonprinting characters are represented by the name of the character in italics and surrounded by angle brackets. This notation is only used where the additional clarity is necessary.


Even though this book does not cover using the shell instructively, it is frequently useful to use the shell interactively to test new ideas. Some of the examples in this book are presented this way. These examples will use the dollar sign ($) as the shell prompt and the greater than sign (>) as the prompt for continuation lines.

$ if command
> ...
> fi
$

Software Included with this Book

Many of the examples in this book are complete, ready-to-use shell scripts. These examples (which include all of the examples in Chapter 9, Examples of Shell Functions, and Chapter 10, Examples of Shell Scripts) are contained on the floppy diskette attached to this book and they are also available electronically from the Prentice Hall FTP server.

The files on the floppy diskette are stored as a tar archive. To extract the files from the floppy diskette, enter the following command:

tar -xvf device

Where device is the name of the floppy diskette device on your system (for example, /dev/fd0). This command will create a subdirectory named shbook that contains the examples from this book. To obtain the examples electronically from the Prentice Hall FTP server, you can use the ftp command to connect to ftp.prenhall. The files are contained in the compressed, tar archive file /pub/blinn/shbook.tar.Z. The following example shows a sample dialog to obtain this file from the Prentice Hall FTP server. The underlined text is the portion of the dialog that you enter, the remainder of the text is the information displayed by the ftp command.

$ ftp ftp.prenhall
Connected to ... 220 ... FTP server (...) ready.
Name (ftp.prenhall:username): anonymous 331 Guest login ok, send ident as password.
Password: username@xxx.xxx.xxx (Your user name and full host name; it will not echo) 230 Guest login ok, access restrictions apply.
ftp> cd /pub/blinn 250 CWD command successful.
ftp> binary 200 Type set to I.
ftp> get shbook.tar.Z 200 PORT command successful.
150 Binary data connection for shbook.tar.Z (n.n.n.n,n) (n bytes).
226 Transfer complete.
n bytes received in n.n seconds (n.n Kbytes/s)
ftp> quit
221 Goodbye
$

After executing this command, the file shbook.tar.Z should be in the current directory. To unpack this file, enter the following commands: uncompress shbook.tar.Z tar -xvf shbook.tar

This will create a subdirectory named shbook that contains the examples from this book.

Product Details

  • Paperback: 288 pages
  • Publisher: Prentice Hall; 1 edition (October 29, 1995)
  • Language: English
  • ISBN-10: 0134514947
  • ISBN-13: 978-0134514949
  • Product Dimensions: 9.2 x 7 x 0.7 inches
  • Shipping Weight: 1.2 pounds (View shipping rates and policies)
  • Average Customer Review: 4.6 out of 5 stars  See all reviews (26 customer reviews)
  • Amazon Best Sellers Rank: #206,680 in Books (See Top 100 in Books)

More About the Author

Discover books, learn about writers, read author blogs, and more.

 

Customer Reviews

26 Reviews
5 star:
 (21)
4 star:
 (3)
3 star:    (0)
2 star:    (0)
1 star:
 (2)
 
 
 
 
 
Average Customer Review
4.6 out of 5 stars (26 customer reviews)
 
 
 
 
Share your thoughts with other customers:
Most Helpful Customer Reviews

12 of 12 people found the following review helpful:
4.0 out of 5 stars Great Shell Programming Intro, June 14, 2003
By 
Kevin Taylor (Wheaton, IL United States) - See all my reviews
(REAL NAME)   
This review is from: Portable Shell Programming: An Extensive Collection of Bourne Shell Examples (Paperback)
The author starts off with the assumption that the reader is technically savvy but has no knowledge of shell scripting. This means that the first chapter necessarily covers basic
syntax such as creating a script file, comments, file name expansion, quotes, control structures, pipes, etc. I found this chapter extremely useful for reviewing the basic building blocks that all shell scripts tend to share. This will be a valuable chapter for someone brand new to shell scripting or Unix-style operating systems. The 4 pages covering quoting was the most lucid coverage I have yet found.

Variable are covered comprehensively in Chapter 2. This chapter covers all the ways of declaring, initializing, assigning and passing variables. It also covers the Borne shell special variables, such as $?, $$, etc. I learned some new techniques for handling uninitialized variables using special Borne shell syntax, such as "${variable:?message}". This statement causes the script to print out the "message" and then terminate if the "variable" is not initialized.

The author next covers shell functions and built-in commands available in Borne shell. The 3 pages on shell functions is adequate to illustrate function syntax. The author also does an adequate job of examining function parameters, variables in functions, strategies for reusing functions and the different effects from executing a function in the current shell versus a subshell. The rest of the book shows numerous examples of functions, so the lack
of function examples here is acceptable. Next the author introduces the important built-in
commands such as : (null), . (dot), eval, exec, read, test, wait, and many others. All of the non-obvious commands have an example or two. Most of these commands are also used extensively in the remainder of the book.

The point of most shell scripts is to manipulate files, so I consider the material in Chapter 4 crucial. This chapter does a fine job of explaining the file descriptors (0,1,2) and redirection of input and output. The author then discusses opening, writing, reading,
closing and truncating files. Finally, "here" documents are covered. This is a nifty feature of Borne shells which allow the creation of "inline" documents.

Borne shells usually depend on the fact that they are running on a Unix-like system. In other words, most shell scripts interface with the operating system. Chapter 5 details how Bourne scripts interact with the environment they are running in. Coverage includes Environment Variables, child versus parent environments, getting user and system information, using signals, and, finally, remote commands. The coverage is not comprehensive, nor could it be. It would take volumes to comprehensively cover the UNIX environment in relation to shell scripts. With that said, the author presents a respectable subset of the most important topics.

The next short chapter first reviews the UNIX command line conventions, e.g. "command [options] [parameters]". The author then discusses the getopt(s) commands for parsing command line parameters and what to do when these commands are not available.

Filters are commands that get their data from the standard input, perform some transformation on the data, and then write the data to the standard output. More than one filter can be strung together to perform very complex transformations. This chapter presents an introduction to this important topic. The tools illustrated are pipes, sed and awk. This chapter, again, only presents an introduction. But the number of examples is impressive and so is the categorization. With this chapter, Chapter 8 and the man pages for sed and awk, a reader will be in a position to infuse his shell scripts with considerable power.

Chapter 9 and 10 are the culmination of the previous 8 chapters. Chapter 9 provides a library of shell functions that I found highly instructive. The list of functions are: CheckHostname, Clear, DownShift, FullName, GetYesNo, IsNewer, IsNumeric, IsSystemType, Prompt, Question, StrCmp, and, finally, SystemType.

The author presents an assortment of shell scripts that are written to be both instructive and useful. As with the functions in Chapter 9, I found these to be highly instructive. The list of scripts are: Cat, DirCmp, Kill, MkDir, Shar, Wc, addcolumn, dircopy, findcmd, findfile, findstr, hostaddr, and, finally, ptree.

No programming language guide would be complete without the obligatory coverage of debugging. This is an area of personal interest to me, because my experience in the industry has taught me that few programmers leave the university with adequate debugging skills. The art of debugging boils down to a set of heuristics for reproducing or capturing an error, narrowing down the potential causes to a manageable set of candidates, and then progressively simplifying until the exact cause of the problem can be understood and corrected. This chapter will not teach the reader to be a competent debugger. The chapter does illustrate common pitfalls that shell scripts contain. It also discusses the basic elements in tracing through a script and even touches on shell scripting style as a tool to reduce bugs. All good, common sense information.

Considering the title of the book, it would be expected that there would be a chapter on portability. This chapter presents some of the best material I have seen assembled on writing portable shell scripts. The author discusses System V versus BSD, subsets of commands, abstraction, locating commands and files, shell features, issues with a number of specific commands, and file and path names. If you are writing production scripts that may be shipped in a heterogeneous environment, this is required reading.

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


12 of 12 people found the following review helpful:
5.0 out of 5 stars One of the best shell programming books I've read!, January 3, 2001
By 
R. EARLS "r.e." (Overland Park, Kansas USA) - See all my reviews
(REAL NAME)   
This review is from: Portable Shell Programming: An Extensive Collection of Bourne Shell Examples (Paperback)
Although I've been shell programming for years, I still learned a lot of new material from this book. Unlike Bill Rosenblatt's book, "Learning the Korn Shell", this book is extremely well thought out and presents subjects in a logical order. I would even recommend this book to people new to shell programming. In addition, unlike most of the other books I've read, ALL of the examples actually work! Mr. Blinn has even taken the time to make sure the examples will work on most every platform (Solaris, HP-UX, ULTRIX, ...).

As the book states, we learn shell programming best by looking at examples of shell scripts. This book is a gold mine of examples which are practical and applicable to a System Administrator's every day job. They really help to reinforce some of the more advanced and/or cryptic shell programming features. Mr. Blinn also does an outstanding job of explaining each shell script in detail. He does not leave the reader guessing or confused.

To be fair, I have to include the fact that the diskette which came with my book was blank. However, by following the instructions in the book I was able to download them from Prentice Hall's FTP site in less than 5 minutes.

Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No


10 of 10 people found the following review helpful:
5.0 out of 5 stars A great book of script examples., August 4, 1998
By A Customer
This review is from: Portable Shell Programming: An Extensive Collection of Bourne Shell Examples (Paperback)
A great book for learning shell scripting. It starts out with general syntax but then the rest of the book in filled with micro examples of things you need to write scripts, like input, output, prompting, changing case, manipulating strings, parsing and extracting data, finding file sizes, checking free space, setting screen echo on/off, read with a timeout, text substitution, doing math, here files, etc. There are also sections on portability, debugging, and common problems. I am very happy with this book and use it often when I am scripting.
Help other customers find the most helpful reviews 
Was this review helpful to you? Yes No

Share your thoughts with other customers: Create your own review
 
 
 
Most Recent Customer Reviews











Only search this product's reviews



What Other Items Do Customers Buy After Viewing This Item?


Tags Customers Associate with This Product

 (What's this?)
Click on a tag to find related items, discussions, and people.
 
(2)
(1)
(1)

Your tags: Add your first tag
 

Sell a Digital Version of This Book in the Kindle Store

If you are a publisher or author and hold the digital rights to a book, you can sell a digital version of it in our Kindle Store. Learn more

Customer Discussions

This product's forum
Discussion Replies Latest Post
No discussions yet

Ask questions, Share opinions, Gain insight
Start a new discussion
Topic:
First post:
Prompts for sign-in
 


Active discussions in related forums
Search Customer Discussions
Search all Amazon discussions
   
Related forums



So You'd Like to...


Create a guide


Look for Similar Items by Category


Look for Similar Items by Subject