Home > Store

UNIX Shell Programmer's Interactive Workbook

Register your product to gain access to bonus material or receive a coupon.

UNIX Shell Programmer's Interactive Workbook

  • Published Dec 22, 1998 by Pearson.

Book

  • Sorry, this book is no longer in print.
Not for Sale

Description

  • Copyright 1999
  • Dimensions: 7 X 9-1/4
  • Pages: 496
  • Edition: 1st
  • Book
  • ISBN-10: 0-13-020064-6
  • ISBN-13: 978-0-13-020064-8


2006D-2

The Hands-On UNIX Learning System That's Fast, Easy & Web-charged!

Master UNIX shell programming now! Start with basic scripts and functions; then learn to execute internal and external commands; use control structures, token splitting, and environment and shell variables. Discover powerful techniques for parameter and command substitution; filename expansion and pattern matching; working with traps; I/O; testing; expression evaluation, and more. Whatever your experience, UNIX Shell Programmer's Interactive Workbook will transform you into a power shell programmer, fast!

Just the facts! No endless, boring discussions here! You'll learn hands-on, through practical exercises, self-review questions and real-world answers. Exclusive "Test Your Thinking" projects guarantee you'll go beyond rote knowledge to really master the subject! It's an integrated learning system that's proven to work!

  • FREE Access to Interactive UNIX Training Web Site
  • Master UNIX shell programming now!
  • Covers the latest Korn Shell
  • Great for sysadmins new to shell programming!
  • Learn through hands-on labs, exercises and projects

Every UNIX Interactive Workbook is fully integrated with its own exclusive Web site, giving you all this and more:

  • "Test Your Thinking" project solutions and detailed explanations.
  • Author's Corner: Your personal connection to this book's expert author.
  • Additional self-review exercises with instant feedback and explanations
  • An exclusive Virtual Study Lounge where you can interact with other students!
  • Dozens of exercises cover the real world tasks that matter most!
  • 100s of self-review questions and answers make sure you understand!
  • Sample exercises and sample self-review questions.

FREE CD-ROM: CBT Systems Tutorial on UNIX Shell Programming!

Sample Content

Downloadable Sample Chapter

Click here for a sample chapter for this book: 0130200646.pdf

Table of Contents

(NOTE: Most chapters end with Test Your Thinking sections).



1. Setting Up.

Set Up for LINUX and Other UNIX Systems. Set Up for MS Windows Systems. Create Directories for Your Programs. Set Up Your Profile and Environment File. Define and Run a Script. "Dot" a Script. Define and Run a Function.

LABS: Running the Current KornShell. Setting Up Your Interactive Environment. Editing and Running Scripts and Functions.



2. Command Syntax.

Identify Command Names. Identify Parameters. Document a Program's Syntax. List All Built-In Commands. Use Two Built-In Tools: print and whence. Execute External Commands. Define Aliases. Write and Run a Simple Function. Redirect stdin and stdout (). Control Clobbering! (>>and>|). Redirect stderr (>). Link File Descriptors for Redirection (n>&). Use a Here Document for stdin (<<).

LABS: Command Parts. Command Types. Redirecting Standard Input and Output.



3. Compound Command Syntax.

Sequential Execution ( ; ). Parallel Execution ( & ). Pipelines ( | ). Conditional Commands && and ||. Co-Processes ( |& ). Group Commands { } and ( ). Use Groups to Control I/O Redirection. Use Groups to Control && and ||.

LABS: Command Sequences. Command Groups.



4. Simple Variables.

Use Proper Terminology. Evaluate Simple Variables. Assign Values to Variables Using =. Use unset to Uninitialize a Variable. Quote the Value Part of an Assignment. Quote Variable References. Quote Single Characters.

LABS: Terminology. Evaluating and Assigning Values. Quoting Variables.



5. Parameters.

Verify Your Set-Up. Pass Parameters to a Function or Script. Use Special Parameter Variables (#@*). Use set to Assign Positional Parameters. Use shift to Access Positional Parameters. Use the getopts Command. Use the optind Variable. Use the optarg Variable. Customize getopts Error Messages.

LABS: Parameters. Process Option Parameters.



6. Advanced Variable Usage.

Declare Numeric Variables and Assign Values. Write Arithmetic Expressions. Use Arithmetic Expansion. Control the Scope of Variables. Use Indexed Arrays. Declare and Use Associative Arrays. Use Compound Variables and Discipline Functions.

LABS: Typed Variables and Scope. Arrays and Compound Variables.



7. Basic Tests.

Write a Simple if, then, ... else statement. Use if to Test the Outcome of External Commands. Use an Alternative Way to Test a Command. Nest if Statements. Use [[ ... ]] In an if Statement. Use {{ ... }} Instead of if. Write Logical Expressions.

LABS: The if Command. The [[ Command ... ]] Operator.



8. Loops.

Use while to Repeat Commands. Use break and continue to Manage a Loop. Use until, a Variant of while. Use for to Work with a List of Values. Use for to Count Iterations.

LABS: Loops: while and until. Loops: List and Arithmetic for.



9. The case and select Statements.

Use the case Command. Use the select Command. Work with select Details.

LAB: The case and select Statements



10. Patterns, Expansions, and Subsitutions.

Use Asterisk ( * ) to Match Zero or More Characters. Use Question Mark ( ? ) to Match a Single Character. Use Square Brackets ( [ ] ) to Match Character Sets. Work with Subpatterns. Use the Output of a Command as the Value of a Variable. Use Command Substitution for the Value of a Parameter. Manage Defaults and Errors. Distinguish Between Null and Unset Variables. Work with Strings and Substrings.

LABS: Patterns. Command Substitution. Parameter Expansion.



11. I/O and Trap Processing.

Use the read Command. Format Output. Use exec to Execute Another Program. Use exec to Open and Close Files. Use exec to Read and Write "Interesting" Devices. Intercept INT and Exit Traps. Use the Debug Trap.

LABS: The read and printf Commands. The exec Command. Intercepting and Generating Traps.



Appendix A: Answers to Self-Review Questions.


Appendix B: Built-In Command Reference.


Appendix C: Glossary.


Index.

Preface

Introduction
Professional and casual programmers alike are finding that scripting languages, such as the KornShell programming language covered in this book, are valuable tools for developing powerful applications while writing a minimal amount of code.

The KornShell is both a scripting language and a command interpreter, which means that you can use the shell's programming features interactively, intermixed with commands you enter to run whatever processing programs you use in your work. UNIX calls its command interpreters shells, and there are a number of them available for UNIX systems besides the KornShell: the Bourne shell (sh), the Bourne-again shell (bash), the C shell (csh), and the TC shell (tcsh) among others. Microsoft Windows also provides rudimentary scripting features with its command interpreters for Windows 95/98 (command.com) and Windows NT/2000 (cmd.exe). The KornShell has the advantages of being a complete implementation of the POSIX shell standard and of being available for a wide range of platforms, including all major UNIX variants as well as for Microsoft Windows systems. The skills you develop as a KornShell programmer will carry over to a wide variety of programming platforms.

What You'll Need
You will need a computer with the current version of the KornShell installed in order to use this book. The first chapter will make sure your system is set up correctly, including how to test whether you have the proper version of the shell and how to get a copy if you don't already have it. Your operating system may be any major version of UNIX, including Linux, or it might be Microsoft Windows, in which case you will also need a software package that enables UNIX programs to run under windows, specifically the U/WIN package which is actively being developed by David Korn (author of the KornShell) at AT&T Research. If you do work in a Windows environment, and if you have a choice about which one to use, you should use Windows NT/2000 because it supports more of the shell's features than either of the "9x" versions. You will also need Internet access to use the book's Companion Web Site that is an integral part of this book.

How This Book is Organized
Don't just read this book! It's an interactive workbook, and the way to use it is to interact with it and with your computer as you work your way through it. Each chapter has one or more Labs, and each Lab has one or more Exercises for you to do. The Exercises are written as a series of questions for you to answer, typically after running some commands on your computer. The answers to all the Exercise questions are given at the end of each Lab, along with an explanation of the concept being developed. Even if you are able to answer a question, you should always check the answer before going on to the next one because there is often explanatory material with the answer that you will need in order to answer the next question. Put a bookmark by the answers so you can get to them easily while working through the questions.

At the end of each Lab there is a set of Self-Review Questions that you can use to check if you are on the right track in mastering the material. The answers to these questions are given in Appendix A. There are additional practice questions for each chapter at the companion Web site for this book.

After the first chapter, which deals with setting up your computer, the remainder of the book introduces the KornShell's programming constructs in what is intended to be a logical sequence of steps. This way of organizing the material was chosen for pedagogical reasons, but it has one characteristic you should be aware of: Some of the earlier material has you do things that you would do differently if you knew the material that comes later on. The goal has been to keep the focus on the part of the language you are learning rather than to introduce extraneous material in order to make each exercise a completely realistic task. The later chapters in the book will give you more realistic problems and solutions to work with.

Appendix B is an alphabetical reference guide to all of the KornShell's built-in commands, extracted from the definitive reference book on the KornShell, "The New KornShell Command and Programming Language" by Morris I. Bolsky and David G. Korn (Prentice-Hall, 1995). The book you are holding tries to cover as much of the KornShell as possible, but there are parts of the language that just don't fit into an introductory workbook. If you find that you want to learn more when you finish this book, the Bolsky and Korn book is the one to get. If you are interested in using the KornShell to develop programs with a Graphical User Interface on UNIX systems, you should also consider "Desktop KornShell Graphical Programming" by J. Stephen Pendergast, Jr. (Addison-Wesley, 1995).

Appendix C is a Glossary, with references back to the chapters. You might find this quicker than the index for tracking down key concepts.

The companion Web site for this book is at:
http://www.phptr.com/phptrinteractive

This Web site is closely integrated with the content of this workbook. Each chapter in the book ends with a set of "Test Your Thinking" exercises designed to give you practice with the material developed in that chapter, but the answers are not given in the book. Rather, you are encouraged to go to the Web site to compare your answers with those of others who are using the book. You will also find additional practice questions for each chapter there, along with hints and "coaching" comments for those questions. Finally, there is also an "Author's Corner" at the Web site where I've put some additional material that wouldn't fit in the book itself, where I will respond to questions about the book, and where I will post corrections to the book's content as needed.

I think of the Web site as a blend of traditional publishing with current trends in asynchronous learning, and I think that you will find it a lively source of help.

There is a CD-ROM packaged with this book called "UNIX: Using the Shell" published by CBT Systems Ltd. Although I was not involved in the development of this CD-ROM, it follows very much the same educational philosophy as this book. You can't just sit back and watch it go by, you have to think and answer questions as you go along. It doesn't provide the depth of coverage for the KornShell that the book does, but it does introduce you to some of the other UNIX shells, namely the Bourne and C shells. There were some technical errors in a pre-publication edition of the CD-ROM that I saw, so be sure to check the Author's Corner of this book's Web site for more information.

Conventions Used in This Book
Variable names and statement types are italicized. Computer output is boldface monospaced. Interactive input and the names of commands are Courier. In Appendix B, the conventions are a little different, where boldface is used to indicate material that you must type as shown. Control codes are shown using normal text. For example, "Control-C" means to press the letter C while holding the "Ctrl" key on the keyboard, and "Newline" means the end-of-line code produced by pressing the "Enter" key on the keyboard.

NOTE : For lines of code in the book, when text that would appear as a single line on your computer screen doesn't fit a single line on the printed page, you will see a false line break, indicated by a backslash character ( \ ), at the end of the first printed line.

Acknowledgements
This book began its life with the help of Jayne Demsky, my Prentice-Hall sales representative at Queens College, who put me in contact with the editorial people at Prentice-Hall PTR. Thank you, Jayne. The Prentice-Hall editors have been a great help, starting with Mark Taub, the series editor, and Jeff Gitlin, the series advisor. Mark and Jeff are the ones who came up with the structure of the interactive workbook series, and Ralph Moore has been the editor who made the format concrete and provided tremendous help in transforming my efforts into a real manuscript. Nick Radhuber in production gets a special vote of thanks for dealing with the time pressures imposed by my submission schedule with grace.

Kevin Wall was the technical reviewer for the book. Kevin has been invaluable in helping me get things right. His understanding of the KornShell is vast and deep, and the book has benefited greatly from his wisdom. I've learned a lot from Kevin, and hope I haven't distorted that knowledge too much in putting it in print.

I've used a computer running Windows NT while writing the book. One window holds the word processor, another one runs a KornShell login to the local computer, another two run xterm logins to KornShell logins on Solaris and DEC OSF/1 computers at Queens College. But the window that deserves special mention here is the one connected to the mail program that manages my subscriptions to the U/WIN users and U/WIN developers news groups. The people using these groups have been great sources of information about KornShell features and programming techniques. With David Korn as an active participant in these groups, they have provided a stimulating environment for working on the book. You know how the author always ends the Acknowledgements by thanking his/her family for their patience and support during the difficult time of writing a book? Well, I can vouch that it's more than just lip service going on here. Many thanks to Nancy, Josh, and Alex for their support during the book's gestation period.

Christopher Vickery
Holliswood, NY
November 1998

About the Author
Christopher Vickery is a professor of computer science at Queen's College of the City University of New York, where he teaches courses in software design and development. His home page on the Web is:
http://baggage.cs.qc.edu

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020