The System Administrator’s Guide to Bash Scripting
Senior Vice President of Content
In this course, you will develop all of the skills needed to write effective and complex shell scripts that can automate mundane tasks and complex implementations. We will walk you through all of the major components and key words in shell scripting (loops, conditionals, functions, error handling, traps, signals and more) so you can effectively write your scripts to handle any situation. You will find a comprehensive study guide, an instructor note card set and a full SIXTEEN PAGES of sample shell scripts developed during the course, all available for your download and reference.
We will present the topics to cover in the course.
History of Bash
A brief history of the Bash Shell and what came before.
Bash Files - .bash_profile
Talking about .bash_profile
Bash Files - .bashrc
Talking about .bashrc
Bash Files - .bash_history
Talking about .bash_history
Bash Files - .bash_logout
Talking about .bash_logout
What Makes a File a Shell Script?
Common characterisitics and requirements for a file to be a script
Displaying Environment Variables in a Script
Introduce how to refer to existing environment variables in a script for display
Using Variables on the Command Line
How to set and use variables in commands
Setting and Using Variables in Scripts
Now that we know how to set and use variables at the command line, translate to our shell scripts
Comment Types and Structure
How do we create private and public comments in our scripts.
We can assign the output of commands to a variable, learn how to use that in our scripts to provide dynamic information.
Command and script exit status
Command line and script arithmetic operations
Global and Local Environment Variables
Show global environment variables and differentiate from local shell instance variables.
Special Characters - Quotes and Escapes
There are a number of special characters at the command line and within scripts, let's learn about quotes, single quotes, escapes and back ticks.
How we can use this special file/directory to hide output when needed
The Read Statement
Up to now, we have provided our own input. Using the 'read' statement, we can prompt our users for it.
Learn how to use brackets and other shortcuts to save time and reference important information quickly.
Types of Variables (Implicit vs. Explicit Definition)
Learn the difference and how to declare them.
Learn what they are, how to declare and use them.
Exercise: Display Environment Variables
Exercise: Setting and Using Variables in Scripts
Exercise: Using Comments
Exercise: Using /dev/null
Exercise: Exit Status Types
Exercise: Evaluating Arithmetic Expressions
Exercise: Command Substitution
Exercise: Interactive Scripting
Exercise: Using Arrays
Passing Variables to Scripts at the Command Line
Learn another way to get information into our scripts.
The If Statement
Learn how to use 'if' to make decisions about how your script executes.
Learn how we can use multiple and nested tests to further lend flexibility to our scripts.
Automatically iterate through lists depending on their length.
We will show how a few lines of code can test for a large array of options.
Learn how to control exactly how many times you iterate through a block of code.
Execution Operators (&& and ||)
Learn how to use these shortcuts to quickly control how your script behaves
Exercise: Passing Variables to Scripts at the Command Line
Exercise: The If Statement
Exercise: Using If/Then/Else
Exercise: The For Statement
Exercise: Using the Case Statement
Exercise: While Looping
Input and Output
Simple method for reading non-binary files and processing the contents.
File Descriptors and Handles
Learn the more "development centric" way of opening our files for reading and writing by assigning them a descriptor for reference.
IFS and Delimiting
This important environment variable will help us process file information once read in using one of the most common situation, delimiting. Example spacedelim.txt file:
Lesson Reference ifsdelim.sh :
i7 4Ghz 32gb 4TB
#!/bin/bash # delimiter example using IFS echo "Enter filename to parse: " read FILE echo "Enter the Delimiter: " read DELIM IFS="read -r $DELIM" while read -r CPU MEMORY DISK; do echo "CPU: $CPU" echo "Memory: $MEMORY" echo "Disk: $DISK" done <"$FILE"
Traps and Signals
Learn how to 'trap' or capture events and redirect how the script is affected by common signals and how they are generated.
Exercise: Reading Files
Exercise: File Descriptors and Handles
Exercise: IFS and Delimiting
Exercise: Traps and Signals
Debugging and Error Handling
Debugging Your Script
How to debug your entire script or just portions of it.
Learn how to test for and react to script errors.
Exercise: Error Handling with Exit
Learn what a function is and the very general definition of one and how to call it.
Structure of Functions in a Script
We need to demonstrate how to organize our scripts now that functions will be playing a part.
Variable Scope in Functions
We will talk about global and local scope of variables and how that applies to functions.
Functions with Parameters
How can we pass parameters into our functions for processing?
What are nested functions and how can we take advantage of them?
Function Return and Exit
Functions can also return information that we can react to and help us with better error handling.
Exercise: Creating a Function
Exercise: Variable Scope in Functions
Exercise: Functions with Parameters
Exercise: Nested Functions
Using the InfoBox
Looking at displaying a pop up notification for user interaction
Display a MessageBox for Confirmation
Pop up a message box to confirm execution
Advanced UI - Building a Menu System
Build a menu system to interact with users and allow choices
Get direct information from users and determine what to do based on it
Learn how to override a system event so we can do clean up and provide custom messages before we exit
Quickly Checking Command Line Parameters
Two easy ways to check that your script receives the correct number of parameters or provide a usage message if not.
Building a Document Generator
In this example, we are going to build a self-executing document reader using the output of ALL scripts we have written in this course.
Exercise: Simple Infobox
Exercise: Displaying a Message Box
Exercise: A User Input Box
Exercise: Creating a Menu
Conclusion and Next Steps
Talk a little about what we have done, where to go from here and how to get there.
Take this course and learn a new skill today.
Transform your learning with our all access plan.Start 7-Day Free Trial