UNIX Shell Programmer's Interactive Workbook with CD-ROM
Authors: Christopher Vickery
Venue:  (1998)

From the Book: 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 youwill 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