EEC Logo


Advanced Korn Shell Programming

Duration: 3 days (projected)

Audience

Individuals requiring a mastery of the command line interface to the UNIX operating system. This includes system administrators, programmers, and power users. This course is a follow-on to the Korn Shell Programming introductory course.

Course Contents

Development of this course is ongoing and the content and duration are subject to change.

  1. Interactive Use of the Shell
    1. Advanced I/O Redirection
      1. Using file descriptors other than 0, 1, and 2
      2. Closing a file descriptor when I/O is complete
      3. Capturing stderr from commands in a pipe
      4. Using I/O redirection with remote commands (such as with ssh)
      5. Examples
    2. Command Line Parsing
      1. Detailed look at the order of evaluation
      2. Using the builtin and command commands
      3. What is eval and how is it used?
      4. Examples
    3. Using Aliases
      1. Aliases as shortcuts for commands
      2. Aliases as shortcuts for entire command lines
      3. Where do aliases appear in the parsing order?
      4. Using aliases in sourced scripts (ie. the . command)
      5. Examples
    4. Command Line Editing
      1. Enabling vi-mode
      2. Recalling previous command lines
      3. Editing using vi commands
      4. Creating edit macros using aliases
      5. Examples
  2. Programming Topics
    1. Command and variable substitution
      1. Old-style (obsolete) syntax
      2. New-style syntax
      3. Single and double quotes: When to use each type
      4. Examples
    2. Data types for variables using typeset
      1. Performance aspects
      2. Functional aspects
      3. When to use printf for formatting
      4. Suggestions for integrating typed variables with read
      5. Examples
    3. Shell functions
      1. Definition: What is a shell function?
      2. Defining shell functions
      3. Using functions in scripts
      4. Building reusable libraries
      5. Examples
    4. Using eval
      1. Examples of the need for eval
      2. Issues related to quoting
      3. Suggestions for how to avoid complicated cases
      4. Examples
    5. Using autoload functions
      1. How to use FPATH and typeset -f together
      2. When the FPATH is searched
      3. Recent changes in the shell regarding autoloaded functions
      4. Examples
    6. Using dot command
      1. What the dot command does
      2. How to build libraries for shell script use
      3. Examples
    7. Arrays
      1. What is an array?
      2. Syntax for creating and accessing arrays
      3. When should arrays be used?
      4. Limits in various implementations
      5. Associative arrays (string instead of numeric subscripts)
      6. Examples
    8. Compound variables
      1. What is a compound variable?
      2. The shell's built-in compound variables
      3. User-defined compound variables: why?
      4. Examples
    9. Testing files
      1. Differences between test, [ ], and [[ ]]
      2. Testing the type of a file
      3. Testing the size of a file
      4. Testing for access to a file (read/write/execute)
      5. Examples
    10. Coprocesses
      1. What is a coprocess?
      2. When are coprocesses useful?
      3. Examples
    11. Program flow control
      1. Review of if, while, for, and case
      2. The until loop
      3. Details of using select for interactive menus
      4. Examples
    12. Debugging programs
    13. Advanced uses of the trap command
      1. How signals are caught using trap
      2. The execution environment of trap handlers
      3. Practical use of trap handlers
      4. Examples
    14. Invocation and environment
      1. What steps does the shell take at startup?
      2. Is the environment cleansed in any way?
      3. Can shell scripts be setuid?
      4. Examples
    15. Performance evaluation and tuning
      1. Why performance matters in shell scripts
      2. Development of a general timing harness
      3. Examples

Course Objectives

Upon completion of this course, the student will be able to write and debug advanced Korn Shell scripts using the following features and more:

Instructional Technique

Students are invited to bring their current ideas and questions to the classroom for discussion. Case studies, lecture, group problem solving, and online laboratories will be used. Students will be encouraged to enhance their skills utilizing the techniques presented through classroom problem solving and controlled online workshops.

Prerequisites

Extensive use of UNIX commands and shell scripting. The student should be thoroughly familiar with directories, file permissions, and using the system editor (such as vi). There is no review of basic features of the shell as covered in the Korn Shell Programming introductory course, so students must be moderately well-versed in shell scripting.