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
Day 1
Overview
Aims and Objectives, Schedule, Introductions, Pre-requisites, Responsibilities
Shell Programming
Objectives, Logging On, Connecting to the Training Server, 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 $(…), 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 - { }
Selection
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, Review Exercise
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, Self Study, for - Iteration using $*, for - at the Command Line, Review Exercise
Menu Creation
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, Self Study, Select Shell Menu
Sub-scripts, Functions and Arrays
Objectives, Sub-Scripts, Export Command, Exit Status, Functions, Creating Functions, Listing Functions, Example Function, Useful Functions, Functions in Scripts, Return Status, Self Study, Using Arrays, Quoted Strings,Summary, Review Exercise I, Review Exercise II
Day 3 (Optional Advanced Topics)
Sed Batch Editor
Objectives, Batch Stream Editor, Regular Expressions, Delete, -d, Print, -p, Suppress, -n, Multiple Input, Text Substitutions, Changing the Delimiter, Extracting Lines, Updating the File, -i, Self Study, Multiple Input, File Input, -f, Quit, -q, Replacing Give Occurrences, Example Script, Real World Examples
Awk 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
Appendix A - 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, Crontab Command, grep - Finding Text in Files, grep - Using Regular Expressions, egrep - Expression grep, Using Filters, Permissions - File and Directory, Permissions - Evaluating, chmod - Changing Permissions, chmod - Octal Numbers, SUID Bit, umask - Default File Permissions, umask - Changing Default Permissions
Course Review
A short review of the whole course
Handouts
Basic Commands, Get By In vim, Get By In nano