An organisation development specialistLinked In

Linux Shell Scripting

Duration 2-3 days

This course gives an introduction to the writing of both Linux and Unix Shell scripts using the Bash shell and to more advanced features including the batch editor sed and the text file processing language awk. Although based on the Redhat (CentOS) version of Linux, the principles learnt may be applied to all other versions of Linux and Unix.

The course takes the format of a workshop, with a mix of lecture, working examples and practical exercises. Although the content may be customised, at least 1 day is normally needed to cover the core elements.

Full course notes are provided along with sample script files and free software tools for use in accessing a Linux/Unix server.

The course is only suitable for those who have a good working knowledge of Linux/Unix or have attended the Introduction to Linux/Unix course.

A natural follow-up to this introductory course would be the Linux or Unix Systems Administration course.  There should be no more than 12 delegates on the course and all delegates should meet the above pre-requisites. Each delegate should have access to a PC running Microsoft Windows with at least 1GB of memory, 20GB of free disc space and a DVD drive. The course uses the free software ORACLE Virtual Box, which may be installed before the course starts if preferred, and a supplied image file. For the trainer, a whiteboard, flipchart and pens are required and an overhead projector that can link to a laptop would be a great help.



Overview, Aims and Objectives, Sample Data, Schedule, Introductions, Pre-requisites, Getting Value, Responsibilities, Self Study Sections, Contents

Shell Programming
Objectives, Creating Shell Scripts, Testing the Command, Creating the Script File, Testing the Script, Adding Execute Permissions, The PATH Variable, Login Files, . - dot Command, Passing Parameters, read Command, read in Scripts, Tidying The Output, Choosing the Shell, Debugging the Script, Review Exercise Special Characters And Variables
Objectives, Quotation Marks, Quotes - Double, Single, Quotes - Single, Escape Character, Quotes - Back, Using $(), Brackets, Regular Expressions - ( ), { } and [ ], Command Substitution - ( ), Sub-shells - ( ) and { }, Brace Expansion - { }, Variables - System, Variables - Special, Variables - User, Variables - unset, Variables in Scripts, Variables - Local, Variables - Global, Variable Constructs - { }, Arrays

Creating Menus
Objectives, case - Condition Test, Menu Creation, while, until - Iteration, sleep - Holding the Output, read - Holding the Output, exit - Ending the Script, break - Ending the Loop, Hidden Option - Forking a shell, trap - Interrupts, trap - Continue, tput - Highlighting Text, Positioning the Cursor - backtab , Select Shell Menu, exec - Running the Script

Objectives, if - Conditional Testing, if - File Attributes, if - Login Files, if – Multiple Tests, elif, if - NOT Condition, if - Multiple Tests, AND and OR, if - Multiple Tests, Nested, if - Testing Strings, if - Using Square Brackets, if - Avoiding Null Input, if - Testing Numbers, Placing Spaces, Read Command, case - Testing Names, if - Testing Commands, Using Variables, Logical Constructs, Review Exercise

Iteration, Looping
Objectives, let - Computations, () - Computations, expr - Computations, while, until - Iteration, Infinite Loop, for - Iteration, Sequence of Numbers, for - at the Command Line, shift - Moving Parameters, for - Iteration using $*, while - Reading a File, while - With a Pipe, Review Exercise

Sub-Scripts And Functions
Objectives, Sub-scripts, Export Command, Exit Status, Functions, Creating Functions, Listing Functions, Example Function, Useful Functions, Functions in Scripts, Return Status, Review Exercise, Review Exercise Extra

Command Sheet by Description, Command Sheet by Command, vi Prompt Sheet

Optional Advanced Content

Batch Editor - Sed
Objectives, Batch Stream Editor, Delete, -d, Regular Expressions, Print, -p, Suppress, -n, Multiple Input, Replacing Text, Extracting Lines, File Input, -f, Quit, -q, Example Scripts, Review Exercise

Processing Text Files - Awk
Objectives, awk Programming Tool, Pattern Matching, Range Patterns, Regular Expressions, Delimiter, Contains, Comparison Patterns, Compound Patterns, Scripts, Troubleshooting Scripts, Built-in Functions, NR > 1 {, Passing Parameters, DEP=$1, Using Contains, DEP=$1, Printf Function, DEP=$1, Computations, Shortcuts, Functions, substr, length, Action Statements, Control Flow Statements, Arrays, Arrays with for Loops, Examples

Appendix A
Objectives, eval Command, More on eval, Passing Arguments, Validating Arguments, getopts Command, getopts Example, Debugging the Script