Advanced Shell Programming
Duration
Three Days
Audience
Technical Users, Applications Programmers, and Systems Programmers requiring an in-depth understanding of the Shell.
Pre-requisites
Introduction to UNIX course or equivalent experience.
Summary
This course provides experienced users of the UNIX System V Bourne Shell with further insights into its effective and efficient use. The student is prepared to design, code, test debug, and excute structured Shell procedures making full use of the basic, as well as the more advanced features of the Shell.
Objectives
Upon successful completion of this course, the student will be able to:
- Describe the Shell Interpreter and how it makes use of the UNIX system calls to execute a procedure
- Describe the order of evaluation of a command line and make use of the evaluation sequence in writing effective Shell procedures
- Use the standard Shell predefined variables, as well as user defined positional and keyword parameters
- Use all of the input/output redirection capabilities of the Shell including redirection involving file descriptors 0 to 9
- Describe and use the Shell invocation options and all of the built in Shell statements
- Write structured, readable, and maintainable Shell procedures that operate in a UNIX-like manner and use the standard UNIX facilities
- Write reliable Shell procedures that properly handle execution time external events and debug these procedures when necessary
- Write more efficient Shell procedures
Course Content
Shell Functionality
- Definitions Shell Interpreter Process
- Process Related System Calls Fork Exec Wait
- Shell Program vs. Compiled Program Process Invocation
- Foreground vs. Background Processes
- Shell Environment Variables
Command Line Evaluation
- Order of Evaluation of Command Line
- Command Grouping Parenthesis ( ) Braces { }
- Pipes Exit Status of Pipe Piping to/from Looping Constructs Piping to/from Conditional Statements
- eval Statement
Parameters & Variables
- Predefined Variables
- $ {*} vs. $ {@}
- Positional Parameters
- set Statement
- Keyword Parameters
- Special Characters
- Quoting Backslash Single Quotes Double Quotes
- Get opt Command
File Descriptors and Redirection
- Definitions File Descriptor File Descriptor Table Redirection
- Multiple Redirections to Same File
- File Creation through Redirection
- Here Documents
- Redirection Using File Descriptors other than 0, 1, and 2
- Using exec Statement to Open Files
Execution Flags and Built-In Statements
- Shell Innovation Flags Restricted Shell (-r) Interactive Shell (-i) Non-execution Shell (-n) Immediate EXIT Shell (-e) Unset Variable EXIT Shell (-u)
- Built-in Statements
Readability and Maintainability
- Comments # vs. : Commenting Standards
- Formatting Conventions Control Structures Here Documents
- Variable Naming and Formatting Conventions
- Error Message Conventions
- EXIT Code Standards
- Standard files and Directories
- Manual Page Creation
Reliability
- Special Substitutions Expression Substitution (:-) Variable Substitution(:=) Undefined Variable EXIT (:?) Variable Reassignment (:+) Omitting the Colon (:)
- Shell Debugging Aids
- Causes for Shell Program Termination Interrupt Processing trap Statement Catching Signals Ignoring Signals Nested Taps
Efficiency
- PATH organization
- Full vs. Relative Pathnames
- Use of Built-in Statements
- Benchmarking Programs
- Optimizing Pipes
- Efficient use of Control Structures
- Recursion
- Shell vs. "C