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, the commands and principles learnt may be applied to all other versions of Linux, including Red Hat, CentOS and SUSE 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-FUNDAMENTALS course.
Outline
Linux Shell Scripting Course Outline
Day 1
Overview
- Aims and Objectives
- Schedule and Introductions
- Pre-requisites
- Responsibilities
Shell Programming
- Creating and testing shell scripts
- Script file creation and permissions (
chmod +x
) $PATH
variable and script location- Login files and the
.
(dot) command - Parameter passing and the
read
command - Output formatting
- Shell selection
- Script debugging
- Review exercise
Special Characters and Variables
- Quotation marks (", ', `)
- Using
$(...)
- System, special, and user variables
- Variable management (
unset
,declare
) - Script variables and scope
- Variable constructs and brackets usage
- Regular expressions
- Command substitution and subshells
Selection
if
statements and conditional testing- File attributes and the
test
command [ ]
syntax and logical constructs- Multiple tests and
elif
- Numeric testing with
(( ))
- String testing
case
statements- Input validation
- Review exercise
Day 2
Iteration and Looping
- Computations (
let
,expr
) while
anduntil
loopsfor
loops and sequence generation- Parameter handling with
shift
- File operations and pipe handling
- Review exercise
Menu Creation
- Implementing menus with
case
statements - Loop constructs
- Output control (
sleep
,read
,exit
,break
) - Shell forking
- Signal handling with
trap
- Text formatting with
tput
select
menus
Functions and Arrays
- Function creation and management
- Return values
- Array operations
- String handling
- Review exercises
Day 3 (Optional Advanced Topics)
Sed Batch Editor
- Stream editing fundamentals
- Regular expressions
- Basic operations (
d
,p
,n
) - Text substitution and pattern replacement
- File handling
- Flow control
Awk Utility
- Pattern matching and regular expressions
- Script creation and debugging
- Built-in functions
- Parameter handling
- Arrays and control flow
- Examples
Advanced Commands
eval
usage and features- Argument handling with
getopts
- Script debugging techniques
Appendix A - Linux Revision
- Shell customization
- Command features
- I/O operations
- Process management
- Text processing
- File permissions
Course Review
- Course summary
- Reference materials
- Basic command review
- Editor basics (vim, nano)