Print this Page

UNIX Korn Shell Programming

Abstract
(3 Days)

This course provides UNIX system users with the fundamentals needed to create shell programs (also called UNIX scripts).  Shell programs are interpreted command files which allow UNIX commands to be embedded in a full programming language, with variables and control logic.  In this way, the execution of a series of UNIX commands can be both automated and executed conditionally.

Shell programming is an important keystone in the development of full application systems in UNIX.

Objectives

Upon completion of this course, students will be able to create, execute, test and debug UNIX Korn shell programs.

Topics

  • Variable definition in the UNIX shell

    • Shell variables

    • Environment variables

    • Variable scope

    • Variable pattern matching and modification

    • Arithmetic using UNIX variables

  • Controlling the UNIX environment via variables

    • Assigning variable values

    • Expanding variables to their values

    • Controlling variable expansion through quotes

    • Predefined UNIX environment variables

  • Korn shell extensions to regular expressions

  • Executing UNIX command functions via a shell program

    • Command return codes

    • Stringing UNIX commands, conditionally and unconditionally

  • Shell control structures - conditional, loops, etc

    • Conditional structures

      • UNIX commands to evaluate conditions – test, expr, [], [[]]

      • If statements

      • If-else statements

      • Case statements

    • Looping structures

      • For loops – definite execution

      • While loops – indefinite execution

      • Select – menu processing

  • Shell programs

    • Parameters and parameter processing

    • Implementing UNIX options

    • Error handling – trap

    • Control blocks

  • Array processing

  • File I/O

    • File redirectors

    • Line I/O – print, read, line

  • Functions

    • Autoloaded functions

  • Debugging techniques

  • Scheduling Shell programs using cron

Supervised Exercises

Shell programs will be assigned after each class session to reinforce the material introduced in the class.  These include a writing and executing a series of Korn shell programs each day.

Prerequisites

Intro to UNIX or a strong knowledge of the executing UNIX commands is required.