Learning the Korn Shell, 2nd Edition

Book description

The Korn shell is an interactive command and scripting language for accessing Unix® and other computer systems. As a complete and high-level programming language in itself, it's been a favorite since it was developed in the mid 1980s by David G. Korn at AT&T Bell Laboratories. Knowing how to use it is an essential skill for serious Unix users. Learning the Korn Shell shows you how to use the Korn shell as a user interface and as a programming environment.Writing applications is often easier and quicker with Korn than with other high-level languages. Because of this, the Korn shell is the most often used shell in commercial environments and among inexperienced users. There are two other widely used shells, the Bourne shell and the C shell. The Korn shell, or ksh, has the best features of both, plus many new features of its own. ksh can do much to enhance productivity and the quality of a user's work, both in interacting with the system, and in programming. The new version, ksh93, has the functionality of other scripting languages such as awk, icon, Perl, rexx, and tcl.Learning the Korn Shell is the key to gaining control of the Korn shell and becoming adept at using it as an interactive command and scripting language. Prior programming experience is not required in order to understand the chapters on basic shell programming. Readers will learn how to write many applications more easily and quickly than with other high-level languages. In addition, readers will also learn about Unix utilities and the way the Unix operating system works in general. The authors maintain that you shouldn't have to be an internals expert to use and program the shell effectively.The second edition covers all the features of the current version of the Korn shell, including many new features not in earlier versions of ksh93, making it the most up-to-date reference available on the Korn shell. It compares the current version of the Korn shell to several other Bourne-compatible shells, including several Unix emulation environments for MS-DOS and Windows. In addition, it describes how to download and build ksh93 from source code.A solid offering for many years, this newly revised title inherits a long tradition of trust among computer professionals who want to learn or refine an essential skill.

Publisher resources

View/Submit Errata

Table of contents

  1. Dedication
  2. A Note Regarding Supplemental Files
  3. Preface
    1. Korn Shell Versions
    2. Summary of Korn Shell Features
    3. Intended Audience
    4. Code Examples
    5. Chapter Summary
    6. Conventions Used in This Handbook
    7. About the Second Edition
    8. We’d Like to Hear From You
    9. Acknowledgments
    10. Acknowledgments from the First Edition
  4. 1. Korn Shell Basics
    1. What Is a Shell?
    2. Scope of This Book
    3. History of Unix Shells
      1. The Korn Shell
      2. Features of the Korn Shell
    4. Getting the 1993 Korn Shell
    5. Interactive Shell Use
      1. Commands, Arguments, and Options
      2. Built-in Help
    6. Files
      1. Directories
        1. The working directory
        2. Tilde notation
        3. Changing working directories
        4. Symbolic links to directories
      2. Filenames and Wildcards
    7. Input and Output
      1. Standard I/O
      2. I/O Redirection
      3. Pipelines
    8. Background Jobs
      1. Background I/O
      2. Background Jobs and Priorities
        1. nice
    9. Special Characters and Quoting
      1. Quoting
      2. Backslash-Escaping
      3. Quoting Quotation Marks
      4. Continuing Lines
      5. Control Keys
  5. 2. Command-Line Editing
    1. Enabling Command-Line Editing
    2. The History File
    3. Emacs Editing Mode
      1. Basic Commands
      2. Word Commands
      3. Line Commands
      4. Moving Around in the History File
      5. Filename and Variable Completion and Expansion
      6. Miscellaneous Commands
      7. Macro Expansion with Aliases
    4. Vi Editing Mode
      1. Simple Control Mode Commands
      2. Entering and Changing Text
      3. Deletion Commands
      4. Moving Around in the History File
      5. Character-Finding Commands
      6. Filename and Variable Completion and Expansion
      7. Miscellaneous Commands
      8. Macro Expansion with Aliases
    5. The hist Command
    6. Finger Habits
  6. 3. Customizing Your Environment
    1. The .profile File
      1. The /etc/profile File
    2. Aliases
    3. Options
    4. Shell Variables
      1. Variables and Quoting
      2. Built-in Variables
        1. Editing mode variables
        2. Mail variables
        3. Prompting variables
        4. Using history command numbers
        5. Terminal types
        6. Command search path
        7. PATH security considerations
        8. PATH and tracked aliases
        9. Directory search path
        10. Miscellaneous variables
    5. Customization and Subprocesses
      1. Environment Variables
      2. The Environment File
    6. Customization Hints
  7. 4. Basic Shell Programming
    1. Shell Scripts and Functions
      1. Functions
        1. Automatically loading functions
        2. POSIX functions
    2. Shell Variables
      1. Positional Parameters
        1. Positional parameters in functions
        2. Changing the positional parameters
      2. More on Variable Syntax
      3. Appending to a Variable
    3. Compound Variables
      1. Compound Variable Assignment
    4. Indirect Variable References (namerefs)
    5. String Operators
      1. Syntax of String Operators
      2. Patterns and Regular Expressions
        1. Regular expression basics
        2. POSIX character class additions
        3. Korn shell versus awk/egrep regular expressions
        4. Pattern matching with regular expressions
      3. Pattern-Matching Operators
      4. Pattern Substitution Operators
        1. Greedy versus non-greedy matching
      5. Variable Name Operators
      6. Length Operators
      7. The .sh.match Variable
    6. Command Substitution
    7. Advanced Examples: pushd and popd
  8. 5. Flow Control
    1. if/else
      1. Exit Status and Return
        1. Return
        2. Advanced example: overriding a built-in command
        3. Pipeline exit status
        4. Interpreting exit status values
      2. Combinations of Exit Statuses
      3. Reversing the Sense of a Test
      4. Condition Tests
        1. String comparisons
        2. About C compilers
        3. File attribute checking
        4. Arithmetic conditionals
    2. for
    3. case
      1. Merging Cases
    4. select
    5. while and until
      1. break and continue
  9. 6. Command-Line Options and Typed Variables
    1. Command-Line Options
      1. shift
      2. Options with Arguments
      3. getopts
        1. More about C compilers
    2. Numeric Variables and Arithmetic
      1. Built-in Arithmetic Functions
      2. Arithmetic Conditionals
      3. Arithmetic Variables and Assignment
    3. Arithmetic for
    4. Arrays
      1. Indexed Arrays
      2. Associative Arrays
      3. Array Name Operators
    5. typeset
      1. Local Variables in Functions
      2. String Formatting Options
      3. Type and Attribute Options
      4. Function Options
  10. 7. Input/Output and Command-Line Processing
    1. I/O Redirectors
      1. Here-Documents
      2. Here-Strings
      3. File Descriptors
        1. Redirector ordering
      4. Special Filenames
    2. String I/O
      1. print
        1. print escape sequences
        2. Options to print
      2. printf
        1. Additional Korn shell printf specifiers
      3. read
        1. Reading lines from files
        2. I/O redirection and multiple commands
        3. Code blocks
        4. Reading user input
        5. Options to read
    3. Command-Line Processing
      1. Brace Expansion and Process Substitution
      2. Substitution Order
      3. Quoting
        1. Extended quoting
      4. eval
        1. The C compiler as pipeline
  11. 8. Process Handling
    1. Process IDs and Job Numbers
    2. Job Control
      1. Foreground and Background
      2. Suspending a Job
      3. Disowning a Job
    3. Signals
      1. Control-Key Signals
      2. kill
      3. ps
        1. System V
        2. BSD
      4. kill: The Full Story
    4. trap
      1. Traps and Functions
      2. Process ID Variables and Temporary Files
      3. Ignoring Signals
      4. Resetting Traps
    5. Coroutines
      1. wait
      2. Advantages and Disadvantages of Coroutines
      3. Parallelization
      4. Coroutines with Two-Way Pipes
      5. Two-Way Pipes Versus Standard Pipes
    6. Shell Subprocesses and Subshells
      1. Shell Subprocess Inheritance
      2. Subshells
  12. 9. Debugging Shell Programs
    1. Basic Debugging Aids
      1. Set Options
      2. Fake Signals
        1. EXIT
        2. ERR
        3. DEBUG
        4. Signal delivery order
      3. Discipline Functions
    2. A Korn Shell Debugger
      1. Structure of the Debugger
        1. The driver script
        2. exec
      2. The Preamble
      3. Debugger Functions
        1. Commands
        2. Stepping
        3. Breakpoints
        4. Break conditions
        5. Execution tracing
        6. Watchpoints
        7. Limitations
      4. A Sample kshdb Session
      5. Exercises
  13. 10. Korn Shell Administration
    1. Installing the Korn Shell as the Standard Shell
    2. Environment Customization
      1. umask
      2. ulimit
      3. Types of Global Customization
    3. Customizing the Editing Modes
    4. System Security Features
      1. Tips for Secure Shell Scripts
      2. Restricted Shell
      3. Trojan Horses
      4. Setuid and Privileged Mode
  14. A. Related Shells
    1. The Bourne Shell
    2. The 1988 Korn Shell
    3. The IEEE 1003.2 POSIX Shell Standard
    4. dtksh
    5. tksh
    6. pdksh
    7. bash
    8. zsh
      1. Extended Globbing
      2. Completion
      3. Command-Line Editor
      4. Prompts and Prompt Themes
      5. Differences Between zsh and ksh
    9. Workalikes on PC Platforms
      1. Cygwin
      2. DJGPP
      3. MKS Toolkit
      4. Thompson Automation Software Toolkit
      5. AT&T UWIN
  15. B. Reference Information
    1. Invocation Options
    2. Built-in Commands and Keywords
    3. Predefined Aliases
    4. Built-in Shell Variables
    5. Test Operators
    6. Options
    7. Typeset Options
    8. Arithmetic
    9. Emacs Mode Commands
    10. vi Control Mode Commands
    11. Using getopts
  16. C. Building ksh from Source Code
    1. Korn Shell Web Sites
    2. What You Can Download
    3. Building ksh
  17. D. AT&T ast Source Code License Agreement
  18. Index
  19. About the Authors
  20. Colophon
  21. Copyright

Product information

  • Title: Learning the Korn Shell, 2nd Edition
  • Author(s): Arnold Robbins, Bill Rosenblatt
  • Release date: April 2002
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596001957