UNIX Shells by Example / Edition 4

Paperback (Print)
Buy New
Buy New from BN.com
$38.09
Used and New from Other Sellers
Used and New from Other Sellers
from $28.71
Usually ships in 1-2 business days
(Save 52%)
Other sellers (Paperback)
  • All (10) from $28.71   
  • New (5) from $33.69   
  • Used (5) from $28.71   

Overview

The world’s #1 shell programming book—now fully updated for Linux and more!

UNIX Shells by Example is the world’s #1 shell programming book, from the world’s #1 shell programming instructor: Ellie Quigley. In UNIX Shells by Example, Fourth Edition, Quigley has thoroughly updated her classic and delivers the information today’s shell programmers need most—including comprehensive coverage of Linux shell programming with bash!

Drawing on 20 years’ experience as a shell programming instructor, Quigley guides you through every facet of programming all leading UNIX/Linux shells: bourne, bash, korn, C, and tcsh. Quigley illuminates each concept with up-to-date, classroom-tested code examples designed to help you jump-start your own projects. She also systematically introduces awk, sed, and grep for both UNIX and GNU/Linux . . . making this the only shell programming book you’ll ever need!

New in this edition:

  • Comprehensive coverage of Linux shell programming with bash
  • Shell Programming QuickStart: makes first-time shell programmers productive in just 15 pages
  • Complete, practical debugging chapter
  • Updated coverage of the latest UNIX and GNU/Linux versions of awk, sed, and grep
  • Shell programming for sysadmins: walks you through key UNIX and Linux system shell scripts
Completely updated:
  • Shell programming fundamentals: what shells are, what they do, how they work
  • Choosing the right shell for any application

Nearly 50,000 UNIX/Linux sysadmins, developers, and power users have used previous editions of UNIX Shells by Example to become expert shell programmers. With UNIX Shells by Example, Fourth Edition, you can, too—even if you’re completely new to shell programming. Then, once you’re an expert, you’ll turn to this book constantly as the best source for reliable answers, solutions, and code.

About the CD-ROM

Comprehensive shell programming code library: all source code and data files for this book’s hundreds of example programs.

Read More Show Less

Editorial Reviews

Booknews
A guide to the C, Bourne, and Korn shells and the awk, sed, and grep Unix utilities, written by a silicon valley instructor. The second edition features more examples. An included CD-ROM contains the source code and data files used in the book. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Read More Show Less

Product Details

  • ISBN-13: 9780131475724
  • Publisher: Prentice Hall
  • Publication date: 9/24/2004
  • Edition description: Book & CD-ROM
  • Edition number: 4
  • Pages: 1150
  • Sales rank: 501,520
  • Product dimensions: 6.98 (w) x 9.26 (h) x 1.78 (d)

Meet the Author

Ellie Quigley is the author of many best-selling books on Linux shells, UNIX shells, and Perl programming. A leading instructor and trainer, her courses in Perl and UNIX shell programming at the University of California Santa Cruz Extension Program, Sun Microsystems, and numerous corporations and colleges have become legendary throughout Silicon Valley. Quigley’s company, Learning Enterprises, Inc., offers on-site training in Unix, Perl, C/C++, Java, and system administration.

Read More Show Less

Read an Excerpt

Playing the “shell” game is a lot of fun. This book was written to make your learning experience both fun and profitable. Since the first edition was published, many of you who have been helped by my book have contacted me, telling me that the book made you realize that shell programming doesn’t need to be difficult at all! Learning by example makes it easy and fun. In fact, because of such positive feedback, I have been asked by Prentice Hall to produce this fourth edition of UNIX® Shells by Example for UNIX and Linux users, programmers, and administrators. Along with updated material throughout, it includes three completely new chapters, with full coverage of the GNU tools for those of you who use Linux. With the meteoric rise of Linux popularity, it seemed like a good time to combine the best of Linux Shells by Example with UNIX® Shells by Example and produce a single volume that touches on all the various aspects of the UNIX/Linux shell world.

The new chapters include Chapter 2, “Shell Programming QuickStart,” an introductory jump-start for programmers who want a quick survey of the shell programming constructs and how they differ; Chapter 15, “Debugging Shell Scripts,” which gives you an example of an error message, what caused it, and how to fix it; and Chapter 16, “The System Administrator and the Shell,” which demonstrates how the shell is used by system administrators, from system boot-up to shutdown.

Writing UNIX® Shells by Example was the culmination of 21 years of teaching and developing classes for the various shells and UNIX/Linux utilities most heavily used by shell programmers. The course notes I developed have been used by the University of California, Santa Cruz; the University of California, Davis; Sun Microsystems; Apple Computer; Xilinx; National Semiconductor; LSI Logic; De Anza College; and numerous vendors throughout the world. Depending upon the requirements of my client, I normally teach one shell at a time rather than all of them at once. To accommodate the needs of so many clients, I developed separate materials for each of the respective UNIX/Linux shells and tools.

Whether I am teaching “Grep, Sed, and Awk,” “Bourne Shell for the System Administrator,” “The Interactive Korn Shell,” or “Bash Programming,” one student always asks, “What book can I get that covers all the shells and the important utilities such as grep, sed, and awk? How does awk differ from gawk? Will this work if I’m using Linux or is this just for Solaris? Should I get the awk book, or should I get a book on grep and sed? Is there one book that really covers it all? I don’t want to buy three or four books in order to become a shell programmer.”

In response, I could recommend a number of excellent books covering these topics separately, and some UNIX and Linux books that attempt to do it all, but the students want one book with everything, and not just a quick survey. They want the tools, regular expressions, all the major shells, quoting rules, a comparison of the shells, exercises, and so forth, all in one book. This is that book.

As I wrote it, I thought about how I teach the classes and organized the chapters in the same format. In the shell programming classes, the first topic is always an introduction to what the shell is and how it works. Then we talk about the utilities such as grep, sed, and awk—the most important tools in the shell programmer’s toolbox. When learning about the shell, it is presented first as an interactive program where everything can be accomplished at the command line, and then as a programming language where the programming constructs are described and demonstrated in shell scripts. (Since the C and TC shells are almost identical as programming languages, there are separate chapters describing interactive use, but only one chapter discussing programming constructs.)

It’s one thing to write a script, but yet another to debug it. I have been working with the shells for so long, that I can recognize bugs in a program almost before they happen! But these bugs are hard to find until you get used to the error messages and what they mean. I added a chapter on debugging to help you understand what the often cryptic error messages mean and how to fix them. Since the diagnostics for the shells may differ, each shell is presented with the most common error messages and what caused them.

Many students take a shell course as a step toward learning system administration. Susan Barr, a teaching colleague of mine who teaches system administration and shell programming, offered to share her extensive knowledge and write a chapter to describe how the system administrator uses the shell (Chapter 16, “The System Administrator and the Shell”).

Having always found that simple examples are easier for quick comprehension, each concept is captured in a small example followed by the output and an explanation of each line of the program. This method has proven to be very popular with those who learned Perl programming from my first book, Perl by Example, or JavaScript from JavaScript(TM) by Example, and with those who learned to write shell programs from UNIX® Shells by Example.

Another aid to comprehension is that the five shells are discussed in parallel. If, for example, you’re working in one shell but want to see how redirection is performed in another shell, you will find a parallel discussion of that topic presented in each of the other shell chapters.

It can be a nuisance to shuffle among several books or the man pages when all you want is enough information about a particular command to jog your memory on how a particular command works. To save you time, Appendix A contains a list of useful UNIX and Linux commands, their syntax, and definitions. Examples and explanations are provided for the more robust and often-used commands.The comparison table in Appendix B will help you keep the different shells straight, especially when you port scripts from one shell to another, and serves as a quick syntax check when all you need is a reminder of how the construct works.

I think you’ll find this book a valuable tutorial and reference. The objective is to explain through example and keep things simple so that you have fun learning and save time. Since the book replicates what I say in my classes, I am confident that you will be a productive shell programmer in a short amount of time. Everything you need is right here at your fingertips. Playing the shell game is fun . . . You’ll see!

Read More Show Less

Table of Contents

Preface.

Acknowledgments.

1. Introduction to UNIX/Linux Shells.

What Is UNIX? What Is Linux? A Little History.

Definition and Function of a Shell.

History of the Shell.

System Startup and the Login Shell.

Processes and the Shell.

The Environment and Inheritance.

Executing Commands from Scripts.

2. Shell Programming QuickStart.

Taking a Peek at Shell Scripts.

Sample Scripts: Comparing the Major Shells.

The C and TC Shell Syntax and Constructs.

The Bourne Shell Syntax and Constructs.

The Korn Shell Constructs.

The Bash Shell Constructs.

3. Regular Expressions and Pattern Matching.

Regular Expressions.

Combining Regular Expression Metacharacters.

4. The grep Family.

The grep Command.

grep Examples with Regular Expressions.

grep with Options.

grep with Pipes.

egrep (Extended grep).

fgrep (Fixed grep or Fast grep).

Linux and GNU grep.

GNU Basic grep (grep -G) with Regular Expressions.

grep -E or egrep (GNU Extended grep).

Fixed grep (grep -F and fgrep).

Recursive grep (rgrep, grep -R).

GNU grep with Options.

grep with Options (UNIX and GNU).

LAB 1: grep Exercise.

5. sed, the Streamlined Editor.

What Is sed?

Versions of sed.

How Does sed Work?

Regular Expressions.

Addressing.

Commands and Options.

Error Messages and Exit Status.

Metacharacters.

sed Examples.

sed Scripting.

LAB 2: sed Exercise.

6. The awk Utility.

What's awk? What's nawk? What's gawk?

awk's Format.

How awk Works.

Formatting Output.

awk Commands from Within a File.

Records and Fields.

Patterns and Actions.

Regular Expressions.

awk Commands in a Script File.

Review.

LAB 3: awk Exercise.

Comparison Expressions.

Review.

LAB 4: awk Exercise.

Variables.

Redirection and Pipes.

Pipes.

Review.

LAB 5: nawk Exercise.

Conditional Statements.

Loops.

Program Control Statements.

Arrays.

awk Built-In Functions.

Built-In Arithmetic Functions.

User-Defined Functions (nawk).

Review.

LAB 6: nawk Exercise.

Odds and Ends.

LAB 7: nawk Exercise.

awk Built-In Functions.

7. The Interactive Bourne Shell.

Introduction.

The Environment.

The Command Line.

Shell Metacharacters (Wildcards).

Filename Substitution.

Variables.

Quoting.

Command Substitution.

An Introduction to Functions.

Standard I/O and Redirection.

Pipes.

The here document and Input.

8. Programming the Bourne Shell.

Introduction.

Reading User Input.

Arithmetic.

Positional Parameters and Command-Line Arguments.

Conditional Constructs and Flow Control.

Looping Commands.

Functions.

Trapping Signals.

The Command Line.

Shell Invocation Options.

LAB 8: Bourne Shell--Getting Started.

LAB 9: Metacharacters.

LAB 10: Redirection.

LAB 11: First Script.

LAB 12: Command-Line Arguments.

LAB 13: Getting User Input.

LAB 14: Conditional Statements.

LAB 15: Conditionals and File Testing.

LAB 16: The case Statement.

LAB 17: Loops.

LAB 18: Functions.

9. The Interactive C and TC Shells.

Introduction.

The Environment.

The C/TC Shell Command Line.

Aliases.

Manipulating the Directory Stack.

Job Control.

Shell Metacharacters.

Filename Substitution.

Redirection and Pipes.

Variables.

Command Substitution.

Quoting.

New Features of the Interactive TC Shell.

The TC Shell Command Line.

TC Shell Command, Filename, and Variable Completion.

TC Shell Spelling Correction.

TC Shell Aliases.

TC Shell Job Control.

Printing the Values of Variables in the TC Shell.

TC Shell Built-In Commands.

Lab 19: The TC Shell--Getting Started.

Lab 20: History.

Lab 21: Shell Metacharacters.

Lab 23: Variables and Arrays.

Lab 22: Redirection.

10. Programming the C and TC Shells.

Introduction.

Reading User Input.

Arithmetic.

Debugging Scripts.

Command-Line Arguments.

Conditional Constructs and Flow Control.

Looping Commands.

Interrupt Handling.

setuid Scripts.

Storing Scripts.

Built-In Commands.

Lab 24: C/TC Shells--Getting Started.

Lab 25: Shell Metacharacters.

Lab 26: Redirection.

Lab 27: First Script.

Lab 28: Getting User Input.

Lab 29: Command-Line Arguments.

Lab 30: Conditionals and File Testing.

Lab 31: The switch Statement.

Lab 32: Loops.

11. The Interactive Korn Shell.

Introduction.

The Environment.

The Command Line.

Commenting and Filename Expansion.

Aliases.

Job Control.

Metacharacters.

Filename Substitution (Wildcards).

Variables.

Quoting.

Command Substitution.

Functions.

Standard I/O and Redirection.

Pipes.

Timing Commands.

12. Programming the Korn Shell.

Introduction.

Reading User Input.

Arithmetic.

Positional Parameters and Command-Line Arguments.

Conditional Constructs and Flow Control.

Looping Commands.

Arrays.

Functions.

Trapping Signals.

Coprocesses.

Debugging.

The Command Line.

Security.

Built-In Commands.

Korn Shell Invocation Arguments.

Lab 33: Korn Shell--Getting Started.

Lab 34: History.

Lab 35: Aliases and Functions.

Lab 36: Shell Metacharacters.

Lab 37: Tilde Expansion, Quotes, and Command Substitution.

Lab 38: Redirection.

Lab 39: Job Control.

Lab 40: Writing the info Shell Script.

Lab 41: Variable Expansion of Substrings.

Lab 42: The lookup Script.

Lab 43: Using typeset.

Lab 44: The if/else Construct and the let Command.

Lab 45: The case Statement.

Lab 46: The select Loop.

Lab 47: Autoloading Functions.

13. The Interactive Bash Shell.

Introduction.

The Environment.

The Command Line.

Job Control.

Command-Line Shortcuts.

Aliases.

Manipulating the Directory Stack.

Metacharacters (Wildcards).

Filename Substitution (Globbing).

Variables.

Quoting.

Command Substitution.

Arithmetic Expansion.

Order of Expansion.

Arrays.

Functions.

Standard I/O and Redirection.

Pipes.

Shell Invocation Options.

Shell Built-In Commands.

Lab 48: bash Shell--Getting Started.

Lab 49: Job Control.

Lab 50: Command Completion, History, and Aliases.

Lab 51: Shell Metacharacters.

Lab 52: Redirection.

Lab 53: Variables.

14. Programming the Bash Shell.

Introduction.

Reading User Input.

Arithmetic.

Positional Parameters and Command-Line Arguments.

Conditional Constructs and Flow Control.

Looping Commands.

Functions.

Trapping Signals.

Debugging.

The Command Line.

bash Options.

Shell Built-In Commands.

Lab 54: bash Shell--First Script.

Lab 55: Command-Line Arguments.

Lab 56: Getting User Input.

Lab 57: Conditional Statements.

Lab 58: Conditionals and File Testing.

Lab 59: The case Statement.

Lab 60: Loops.

Lab 61: Functions.

15. Debugging Shell Scripts.

Introduction.

Style Issues.

Types of Errors.

Probable Causes for Syntax Errors.

Tracing with Shell Options and the set Command.

Summary.

16. The System Administrator and the Shell.

Introduction.

The Superuser.

Becoming a Superuser with the su Command.

Boot Scripts.

Summary.

A. Useful UNIX/Linux Utilities for Shell Programmers.

B. Comparison of the Shells.

The Shells Compared.

tcsh versus csh.

bash versus sh.

Index.

Read More Show Less

Preface

Playing the “shell” game is a lot of fun. This book was written to make your learning experience both fun and profitable. Since the first edition was published, many of you who have been helped by my book have contacted me, telling me that the book made you realize that shell programming doesn’t need to be difficult at all! Learning by example makes it easy and fun. In fact, because of such positive feedback, I have been asked by Prentice Hall to produce this fourth edition of UNIX® Shells by Example for UNIX and Linux users, programmers, and administrators. Along with updated material throughout, it includes three completely new chapters, with full coverage of the GNU tools for those of you who use Linux. With the meteoric rise of Linux popularity, it seemed like a good time to combine the best of Linux Shells by Example with UNIX® Shells by Example and produce a single volume that touches on all the various aspects of the UNIX/Linux shell world.

The new chapters include Chapter 2, “Shell Programming QuickStart,” an introductory jump-start for programmers who want a quick survey of the shell programming constructs and how they differ; Chapter 15, “Debugging Shell Scripts,” which gives you an example of an error message, what caused it, and how to fix it; and Chapter 16, “The System Administrator and the Shell,” which demonstrates how the shell is used by system administrators, from system boot-up to shutdown.

Writing UNIX® Shells by Example was the culmination of 21 years of teaching and developing classes for the various shells and UNIX/Linux utilities most heavily used by shell programmers. The course notes I developed have been used by the University of California, Santa Cruz; the University of California, Davis; Sun Microsystems; Apple Computer; Xilinx; National Semiconductor; LSI Logic; De Anza College; and numerous vendors throughout the world. Depending upon the requirements of my client, I normally teach one shell at a time rather than all of them at once. To accommodate the needs of so many clients, I developed separate materials for each of the respective UNIX/Linux shells and tools.

Whether I am teaching “Grep, Sed, and Awk,” “Bourne Shell for the System Administrator,” “The Interactive Korn Shell,” or “Bash Programming,” one student always asks, “What book can I get that covers all the shells and the important utilities such as grep, sed, and awk? How does awk differ from gawk? Will this work if I’m using Linux or is this just for Solaris? Should I get the awk book, or should I get a book on grep and sed? Is there one book that really covers it all? I don’t want to buy three or four books in order to become a shell programmer.”

In response, I could recommend a number of excellent books covering these topics separately, and some UNIX and Linux books that attempt to do it all, but the students want one book with everything, and not just a quick survey. They want the tools, regular expressions, all the major shells, quoting rules, a comparison of the shells, exercises, and so forth, all in one book. This is that book.

As I wrote it, I thought about how I teach the classes and organized the chapters in the same format. In the shell programming classes, the first topic is always an introduction to what the shell is and how it works. Then we talk about the utilities such as grep, sed, and awk—the most important tools in the shell programmer’s toolbox. When learning about the shell, it is presented first as an interactive program where everything can be accomplished at the command line, and then as a programming language where the programming constructs are described and demonstrated in shell scripts. (Since the C and TC shells are almost identical as programming languages, there are separate chapters describing interactive use, but only one chapter discussing programming constructs.)

It’s one thing to write a script, but yet another to debug it. I have been working with the shells for so long, that I can recognize bugs in a program almost before they happen! But these bugs are hard to find until you get used to the error messages and what they mean. I added a chapter on debugging to help you understand what the often cryptic error messages mean and how to fix them. Since the diagnostics for the shells may differ, each shell is presented with the most common error messages and what caused them.

Many students take a shell course as a step toward learning system administration. Susan Barr, a teaching colleague of mine who teaches system administration and shell programming, offered to share her extensive knowledge and write a chapter to describe how the system administrator uses the shell (Chapter 16, “The System Administrator and the Shell”).

Having always found that simple examples are easier for quick comprehension, each concept is captured in a small example followed by the output and an explanation of each line of the program. This method has proven to be very popular with those who learned Perl programming from my first book, Perl by Example, or JavaScript from JavaScript(TM) by Example, and with those who learned to write shell programs from UNIX® Shells by Example.

Another aid to comprehension is that the five shells are discussed in parallel. If, for example, you’re working in one shell but want to see how redirection is performed in another shell, you will find a parallel discussion of that topic presented in each of the other shell chapters.

It can be a nuisance to shuffle among several books or the man pages when all you want is enough information about a particular command to jog your memory on how a particular command works. To save you time, Appendix A contains a list of useful UNIX and Linux commands, their syntax, and definitions. Examples and explanations are provided for the more robust and often-used commands.The comparison table in Appendix B will help you keep the different shells straight, especially when you port scripts from one shell to another, and serves as a quick syntax check when all you need is a reminder of how the construct works.

I think you’ll find this book a valuable tutorial and reference. The objective is to explain through example and keep things simple so that you have fun learning and save time. Since the book replicates what I say in my classes, I am confident that you will be a productive shell programmer in a short amount of time. Everything you need is right here at your fingertips. Playing the shell game is fun . . . You’ll see!

Read More Show Less

Customer Reviews

Average Rating 5
( 1 )
Rating Distribution

5 Star

(1)

4 Star

(0)

3 Star

(0)

2 Star

(0)

1 Star

(0)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing 1 Customer Reviews
  • Posted December 22, 2009

    Gentle Introduction to Shells

    I bought this book primarily because of the way it was organized with description of a command, example of the command in use, and an explanation of how the command was processed. Bonus that it covers a wide variety of shells (C/TCSH, BASH, KCSH, etc) so I was able to work through examples with the specific syntax of the shell that I was using.

    For a new shell user, one of the most frustrating things is to get the syntax and structure of a command right. Sometimes I found myself trying to implement a solution, only to find out that it was in the syntax for a different shell - this book helped lift the fog and has enabled me to work more efficiently.

    I recommend this book for any late-comers to shell scripting that are confused by the differences in shells, shell specific syntax, and/or logical structure of how the shells work. It may also be good as a reference for those that are more advanced, but I'm not one of those people yet.

    Was this review helpful? Yes  No   Report this review
Sort by: Showing 1 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)