did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

did-you-know? rent-now

Amazon no longer offers textbook rentals. We do!

We're the #1 textbook rental company. Let us show you why.

9780201563245

KornShell Programming Tutorial

by
  • ISBN13:

    9780201563245

  • ISBN10:

    020156324X

  • Edition: 1st
  • Format: Paperback
  • Copyright: 1991-07-01
  • Publisher: Addison-Wesley Professional
  • Purchase Benefits
  • Free Shipping Icon Free Shipping On Orders Over $35!
    Your order must be $35 or more to qualify for free economy shipping. Bulk sales, PO's, Marketplace items, eBooks and apparel do not qualify for this offer.
  • eCampus.com Logo Get Rewarded for Ordering Your Textbooks! Enroll Now
List Price: $49.99

Summary

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.



020156324XP04062001

Author Biography

Barry Rosenberg is an independent technical writer and a software instructor for Technology Exchange Company. He is the author of more than 30 programming manuals, including Addison-Wesleyis Client/Server Computing for Technical Professionals: Concepts and Solutions and KornShell Programming Tutorial.

020156324XAB04062001

Table of Contents

List of Tables
List of Figures
Preface
That No One Will Ever Read
Author's Note Regarding the ksh93 Edition
Before Writing Your First KornShell Scripts
Getting Started
What Shell Is Executing My Script?
Operating System Commands in a Shell Script
Beware: Are You Allowed to Execute This Script?
Commenting Your Code
Beware: Picking a Bad Name for Your Script
The Usage Line
Simple Output
Variables
Beware: Variable Names Are Case Sensitive
Simple Input
Obtaining the Value of a Variable
Beware: The Dollar Sign in Read Statements
Newlines, Semicolons, White Space, and Columns
Beware: Confusing + and -
Assigning a Value to a Variable
Beware: Common Mistakes When Assigning Variables
Finding Your Mistakes
Can I Quote You on That?
Data Types
If You're New to Programming
If You're an Experienced Programmer
Declaring Strings
Declaring Integers
Binary, Octal, Hex, and So On
Declaring Floats
Declaring Constants
Declaring nameref Variables
Declaring Arrays
Declaring Arrays with set -A
Printing Array Values
Beware: Common Array Mistakes
Declaring Associative Arrays
Probing Arrays
Declaring Structures Part I
Declaring Structures Part II
Arrays of Structures
Math
If You're New to Programming
If You're an Experienced Programmer
Double Parentheses
Integer Addition, Subtraction, and Multiplication
Integer Division
Floating-Point Math
Mixing Floating-Point and Integer Math
Grouping Mathematical Operations
Beware: Common Mistakes in Math Operations
Mathematical Assignment Operators
The Triggy Stuff
Beware: Math Functions Inside Double Parentheses
A Practical Math Example
Math Operator Summary
Pattern Matching. If You're New to Programming
If You're an Experienced Programmer
For Everyone
The ? Wildcard
The [char1char2...charN] Wildcard
Character Classes
The * Wildcard
Beware: Matching Filenames
The ?(pattern1p. attern2..
Beware: White Space within Patterns
The @(pattern1p. attern2..
The !(pattern1p. attern2..
The +(pattern1p. attern2..
The !(subpattern1
Matching Subpatterns with \d
Simple Commands Containing Patterns
Wildcard Summary
Conditions
If You're New to Programming
If You're an Experienced Programmer
Tests on Numbers and Strings
Comparing Numbers with if
Beware: Common Mistakes Using if with Numbers
Comparing Numbers with the ? : Operator
Beware: Common Mistakes in ? : Compound Statements. else and elif
Comparing Strings with if
Comparing Alphabetical Order with < and >
Comparing a String to a Pattern with if
Beware: Common Mistakes Comparing
Table of Contents provided by Publisher. All Rights Reserved.

Supplemental Materials

What is included with this book?

The New copy of this book will include any supplemental materials advertised. Please check the title of the book to determine if it should include any access cards, study guides, lab manuals, CDs, etc.

The Used, Rental and eBook copies of this book are not guaranteed to include any supplemental materials. Typically, only the book itself is included. This is true even if the title states it includes any access cards, study guides, lab manuals, CDs, etc.

Excerpts

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-

Rewards Program