The Linux Shell and Shell Scripting

Objectives

On completion of this course, delegate will:

Approach

This course is part lecture, part hands-on.

Prerequisites

Delegates must have completed the Linux Essentials course, or have good experience in using the Linux command line.

Equipment

The course may be run either:

Detailed instructions for machine setup will be provided once the platform has been agreed.

Course Outline

Linux/ Unix Review

  • Brief recap of Linux/Unix architecture and concepts

What is the Shell?

  • Shell Responsibilities
  • Program Execution
  • Filename Substitution
  • Variable Expansion
  • Environment Variables
  • Quoting

I/O Redirection

  • stdin, stdout & stderr
  • Device Files
  • Here Documents
  • Pipes & Filters

Building Commands using Filters

  • Examples of powerful commands built simply
  • head, tail
  • sort, cut
  • wc
  • grep family
  • xargs
  • pv

Regular Expressions and sed

  • Regular Expressions Intro
  • BREs (Basic Regular Expressions)
  • EREs (Extended Regular Expressions)
  • sed

Command Substitution

  • Building commands from other commands
  • Useful commands to use with command substitution
  • Command substitution in more recent shells

Shell Scripts

  • What is a Shell Script?
  • Invoking Shell Scripts
  • Permissions
  • Comments
  • Which Shell gets run?

Shell Programming

  • Passing Arguments from the Command Line
  • Grouping Commands

Making Decisions

  • Exit Status
  • if Statement
  • Testing Conditions
  • read command
  • Arithmetic
  • case Statement

Loops

  • Benefits and Uses of Loops
  • for Loop
  • Three-expression for Loop
  • Infinite Loops
  • Conditional Exits with break
  • Continuation with continue
  • while Loop
  • until Loop

Functions

  • Declaring a Function
  • Calling a Function
  • Parameters within Functions
  • Local Variables
  • Returning from Functions

Processes

  • Background tasks
  • sleep
  • wait
  • signals & interrupt handling
  • trace
  • timing

Advanced I/O

  • Redirecting loops & grouped commands
  • Manipulating File Descriptors
  • Network Communications in bash

Further Parameter Expansion

  • Defaults & Pattern Matching

Wrap-Up