Among its key features, the book:
"This book is full of useful examples which will benefit anyone interested in programming in KornShell, especially novices."-David Korn, AT&T Bell Labs, Creator of KornShell
The KornShell is the most important shell or interface, for the 1990's. It runs on the UNIX, OSF-1, MS-DOS, OS/2, and VMS operating systems. It supports every feature of the Bourne shell, and incorporates many of the good C shell features. If you program, you need the KornShell. If you want to learn the KornShell, you need this book.
Barry Rosenberg makes learning and using the KornShell easy by writing in a light, humorous style. The book is packed with short non-trivial examples of shell scripts. Common programming pitfalls and their solutions are boldly highlighted in BEWARE sections throughout. Many chapters begin with sections of helpful hints for new programmers and for experienced programmers.
Among its key features, the book:
Research indicates that virtually no one actually reads prefaces in computer books. In fact, this preface could be about the Loch Ness Monster for all most readers care.
But why don't people read prefaces? Is it because prefaces sometimes get too personal? ("..and I want to thank Sal, who made this book possible.") Is it because the sentiments of nerdy authors can be a bit repulsive? ("..Sal, my MicroVAX, was always there when I needed her.") Is it because they are predictably self-deprecatory in an ironic way? ("..and I want to thank: list of 250 noted experts goes here for reviewing drafts of this manual. Naturally all mistakes are my own.") No, when it comes right down to it, people avoid prefaces because they're boring.
It is also de rigueur for the nerdish author to explain, folksinger style, why he or she decided to write this piece. I guess this book sort of came to me while I was camping out in the glorious Rocky Mountains. I was gazing at pristine waterfalls and awe-inspiring sunsets when I said to myself, "This land must be preserved. I shall write a KornShell book." Possessed by a demonic ecological fervor, I roared down that mountain in a snowmobile, fired up a 1200 watt workstation, and wrote it all down for you. I only ask that you use the power of the KornShell for good, rather than evil.
Actually, I've been writing programming manuals for many years under the pen name "Apollo Computer Inc." Recently, my agent insisted that I change it to "Hewlett-Packard Company," presumably because it sounded less ethnic. Through the years, I've been lucky enough to get lots of feedback from my readers. What do you think they ask for? More text? No. More syntax? Definitely not. When it comes right down to it, readers consistently ask for only one thing: more examples.
So, I listened to them and based this tutorial entirely on examples.
I feel that short, focused examples are more valuable than long, detailed examples, and I've written the book accordingly. The purpose of the book is not to make me look clever; it is to make you look clever. Nevertheless, I've sprinkled a few lengthy examples into the mix for those of you who enjoy that sort of thing.
When I was a mere lad my family doctor pointed to a massive encyclopedia of pharmaceuticals and told me that he could treat 90% of all patients with only six different medicines. Similarly, although the KornShell is a very rich language, my goal is to focus on the common script ailments and to leave the beriberi treatment to specialists.
Beginners may be wondering, " Is this book too hard for me?" No, probably not. Programmers experienced in various languages, though not in the KornShell, are probably wondering, "Is this book too wimpy for me?" No, probably not. To help guide both kinds of readers through the book, I've marked certain sections as being more appropriate for one group or the other. Beginners don't need an explanation of traps and experienced programmers already know what loops are.
Here's how I've organized the book:
Chapter 1 introduces the KornShell and its features.
Chapter 2 contains some simple KornShell scripts to get you started.
Chapter 3 discusses data types.
Chapter 4 shows you how to do simple math.
Chapter 5 illustrates pattern matching.
Chapter 6 explains how to evaluate conditions.
Chapter 7 shows you how to set up loops.
Chapter 8 describes how to create simple menus.
Chapter 9 explains how to evaluate command line arguments.
Chapter 10 illustrates functions.
Chapter 11 has a lot of conceptual stuff in it about environments and inheritance. It also contains some sample start-up scripts.
Chapter 12 examines input and output.
Chapter 13 focuses on string manipulation.
Chapter 14 describes the many variables that are part of the KornShell.
Chapter 15 describes various advanced features of the KornShell. (This chapter is aimed at the sophisticated programmer.)
Chapter 16 contains a half-dozen lengthy KornShell examples.
Chapter 17 explains command line editing and the history file.
Appendix contains a syntactic quick reference. This appendix will become more valuable to you as your KornShell experience increase.
Since the KornShell runs on all sorts of operating systems, I've tried to keep operating system dependencies to a bare minimum. Nevertheless, my sense is that the majority of KornShell users are either working under the UNIX operating system or are at least marginally familiar with it. Therefore, in the examples that do contain commands, I've picked UNIX commands.
It is now time for the obligatory not to the tools that made this book possible. I used the
\fBtroff\fR.mm macro package to format drafts of this book (an experience akin to running blindfold through nettles) and then came to my senses and converted the whole thing to Interleaf TPS. //cascade, my trusty Apollo DN4000 workstation, was always there when I needed her. It practically goes without saying that I created camera-ready copy for the book on a Hewlett-Packard laser printer.
My three primary reviewers were KornShell gurus David Korn, Steve Sommars, and Glenn Fowler, all of whom gave fantastic and diplomatic criticism.
I also received important criticism and help from Tom Barstow, Dave Beckedorf, Bart Hanlon, Warren Johnson, Ed Johnston, Mark Keil, Mike Kong, Alice Lynch, Dave Penfield, Will Roaf, Frank Rubinsky, John Weiss, Daryl Winters, Teri Witham, and other people whose names I have no doubt forgotten to list. Eric Eldred and Quentin Sullivan found so many bugs in early drafts that, and I mean this as a compliment, they should have a brand of insecticide named after them.
Judy Tarutz is my long-suffering editor. In person, Judy is a kind, gentle soul with an outrageous sense of humor. Give her a red pen though, and she turns into Conan the Barbarian. Her savage red pen cut a bloody swath through early drafts of this book. If we should chance to meet up one day, dear reader, I'll tell you all the "weak" jokes she made me take out.
I'd also like to thank the members of the Academy.
A consortium of great minds-those minds owned and operated by Ted Ricks, John Wait, Jack Danahy, and Steve Spicer-led me to the KornShell and helped me define the material for this book.
Finally, I'd like to thank the person who really made this book possible: my wife and best friend, Marilyn.
Whoops, almost forgot. Naturally, all mistakes are my own.