Linux Shell Scripting

Part of our "DevOps" courses

2 days

Course Overview

This course gives an introduction to the writing of Linux shell scripts using the Bash shell. The course is suitable as preparation for the RHCSA and CompTIA Linux+ examinations.

An editor will be used to create and test shell scripts which will cover the use of variables and arrays, select statements, loop constructs, sub-scripts and functions. Although based on Ubuntu or Redhat (CentOS) Linux, the commands and principles learnt may be applied to all other versions of Linux, including SUSE, Mint and Arch and to all versions of Unix including Solaris and AIX.

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 2 days are normally needed to cover the core elements.

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

Course Prerequisites

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


Day 1


Aims and Objectives, Schedule, Introductions, Pre-requisites, Responsibilities

Linux Revision

Objectives, Customising the Shell, . - dot Command, Getting Help, Command History, Command Completion, Piping - using | symbol, Redirection - using > symbol, Redirection - using >> symbol, Redirection of Errors - using 2> symbol, Wildcards - File Name Generation, Wildcards - using *, Wildcards - using ?, Wildcards - using , Foreground Jobs, Background Jobs - &, kill - Stopping Jobs, jobs - Job Control, Scheduling Jobs, Crontab Command, Finding Text in Files, grep - Using Regular Expressions, egrep - Expression grep, Using Filters, More Regular Expressions, Regular Expression Examples, chmod - Changing Permissions, chmod – Octal Numbers

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

Special Characters and Variables

Objectives, Quotation Marks, Quotes - Double, Single, Quotes - Single, Escape Character, Quotes - Back, Using $(…), Variables - System, Variables - Special, Variables - User, Variables - unset, Variables - declare, Variables in Scripts, Variables - Local, Variables - Global, Variable Constructs - { }, Brackets, Regular Expressions - ( ), { } and , Command Substitution - ( ), Sub-shells - ( ) and { }, Brace Expansion - { }, Other Variable Constructs - { }


Objectives, if - Conditional Testing, if - File Attributes, if - Using Test, if - Single Square Brackets , If - Logical Constructs [ ], if - Multiple Tests, elif, if - NOT Condition, if - Multiple Tests, AND and OR, if - Multiple Tests, Nested, if - Testing Numbers, if - Testing Numbers with (( )), if - Testing Strings, if – Which Construct To Use?, Placing Spaces, Read Command, case - Testing Names, Input validation, If – Regular Expressions, if - Testing Commands, Using Variables

Day 2

Iteration, Looping

Objectives, let - Computations, () - Computations, expr - Computations, while, until - Iteration, Infinite Loop, for - Iteration, Sequence of Numbers, shift - Moving Parameters, while - Reading a File, while - With a Pipe, for - Iteration using $*, for - at the Command Line, 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 \b, exec - Running the Script, Select Shell Menu

Arrays, Sub-scripts and Functions

Objectives, Using Arrays, Quoted Strings, Sub-scripts, Export Command, Exit Status, Functions, Creating Functions, Listing Functions, Example Function, Useful Functions, Functions in Scripts, Return Status, Summary

Day 3 (Optional Advanced Topics)

Sed Utility

Objectives, awk Programming Tool, awk - Pattern Matching, awk - Regular Expressions, awk - Delimiter, awk - Contains, awk - Range Patterns, awk - Comparison Patterns, awk - Compound Patterns, awk - Scripts, awk - Troubleshooting Scripts, awk - Built-in Functions, awk - Passing Parameters, awk - Using Contains, awk - Printf Function, awk - Computations, awk - Shortcuts, awk - Functions, substr, length, Self Study, awk - Action Statements, awk - Control Flow Statements, awk - Arrays, awk - Arrays with for Loops, awk - Examples

Advanced Commands

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

This Linux Shell Scripting course looks very interesting, I do however have a question