2 Day – Linux Shell Scripting

A 2 day course describing how to develop Linux shell scripts using the programming features of the Bash or Korn shells. This course is an introduction to the shell command line as a programming language, command line parsing, conditional flow control, looping and process substitution. The focus is on obtaining a basic understanding of writing robust shell scripts.

Prerequisites

The course is designed for staff with experience of the Linux command line who are able to edit and save text files. A basic knowledge of the Linux shell command line including filename wildcards, I/O redirection and quotes is essential, while programming constructs such as variables and flow control obtained from prior experience of another scripting or programming language is useful but not required.

Learning Objectives

The course will introduce staff to the basic principles of writing and running Linux shell scripts, specifically:

  • Writing, debugging and tracing shell scripts
  • Making decisions with the if and test commands
  • Looping with the for and while commands
  • Accessing command line arguments
  • Using advanced variable and command substitution
  • Developing user input menus
  • Working with pipelines and simple filter commands

Delivery

This course comprises a mix of theory, demonstrations and hands on exercises. Approximately 50% of the time is hands-on.

Day 1 – Core Concepts & Flow Control

  • Creating and executing scripts
  • Using the #! (shebang) construct
  • The source (dot) command
  • Debugging and tracing scripts
  • Setting shell options
  • The process status exit
  • The if command
  • The test command and [[
  • The while command
  • The for command
  • Accessing command line arguments
  • Break and continue commands

Day 2 – Command line & Filters

  • Variable substitution
  • Advanced substition with ${ }
  • Command substitution (backquotes)
  • The shift command and $*/$@
  • The && and || command separators
  • Compound I/O redirection
  • User menus with select
  • The case command
  • Pipelines and simple filters
  • Regular expression concepts
  • Stream editing