About the course
Bash is the default shell on most Linux systems and a powerful tool for automating tasks, managing files, and executing commands efficiently from the command line. This course provides a focused introduction to the essential fundamentals of Bash scripting, specifically designed for individuals with basic Linux command line experience who want to start automating their workflow and prepare for Linux administration tasks.
You will learn how to create and execute your own Bash scripts, work with variables and data, and master fundamental control flow structures including conditional statements (if, case) and loops (for, while). A key focus will be placed on essential scripting techniques like using pipes (|) and redirection (>, <), performing command substitution ($(command)), processing command-line arguments, and understanding command exit status for basic error handling ($?, set -e).
Through practical examples and hands-on exercises, you will gain a solid understanding of the core Bash scripting concepts needed for daily tasks and system management. By the end of the course, you will have the confidence to write basic, effective scripts to automate common operations, laying a crucial foundation for more advanced Linux usage and administration.
Instructor-led online and in-house face-to-face options are available - as part of a wider customised training programme, or as a standalone workshop, on-site at your offices or at one of many flexible meeting spaces in the UK and around the World.
-
- Explain the role of Bash and navigate the Bash environment.
- Create and execute basic Bash scripts.
- Work with variables and perform basic string manipulation and parameter expansion.
- Use input/output redirection and pipes to combine commands.
- Perform command substitution to use command output in scripts.
- Understand command exit status and implement basic error handling (set -e).
- Process command-line parameters and parse simple options (getopts).
- Implement conditional logic using if, case, and [[ ... ]] tests.
- Create loops (for, while) for iterating over data or commands.
- Define and use simple functions to organise script code.
- Apply basic script hygiene and best practices.
-
This course is designed for individuals with basic Linux command line experience who want to learn the fundamentals of Bash scripting for automation and administration preparation. It is ideal for:
Linux users looking to automate repetitive tasks.
Developers needing to write scripts for build processes or deployments.
IT Support staff performing routine system operations.
Individuals preparing for Linux Administration roles who need scripting foundations.
Anyone looking to gain proficiency in command-line automation.
-
Participants should have attended our Intro to Linux course or have equivalent experience, including:
Working knowledge of essential Linux command line basics (navigating the filesystem, executing basic commands like ls, cd, mv, cp, rm, man).
Familiarity with a text editor (e.g., nano, vim, VS Code).
No prior experience with Bash scripting is required.
-
This Linux Bash scripting course is available for private / custom delivery for your team - as an in-house face-to-face workshop at your location of choice, or as online instructor-led training via MS Teams (or your own preferred platform).
Get in touch to find out how we can deliver tailored training which focuses on your project requirements and learning goals.
-
Introduction to Bash and the Environment
What is Bash? Understanding the role of the shell in Linux system interaction and scripting.
Refresher of Essential Linux Commands (Building on assumed basic knowledge: file manipulation, navigation, process listing).
Understanding the Command Structure: Commands, arguments, options.
The Bash Environment:
Shell Variables vs. Environment Variables.
Using Command History effectively.
Using Here Documents (<<EOF) for multi-line input redirection in scripts.
Working with Variables and Data
Creating and using Bash Variables: Assignment and accessing values.
Variable Expansion: Understanding how variables are interpreted.
Essential Parameter Expansion: Using common forms like ${variable:-default_value} for setting defaults.
Basic String Manipulation: Getting the length of a string, basic substring extraction.
Using the declare command for variable attributes (e.g., making variables read-only).
Arrays: Declaring and accessing simple indexed arrays.
Scripting Fundamentals: Execution, Input/Output, and Flow
Creating your First Bash Scripts: Using the shebang (#!/bin/bash), making scripts executable.
Executing Scripts.
Debugging Bash Scripts: Using set -x for tracing script execution.
Input/Output Redirection: Redirecting command output (>, >>) and input (<). Understanding 2>&1 for redirecting standard error.
Pipes (|): Combining commands by directing the output of one to the input of another.
Command Substitution ($(command)): Using the output of a command within a script.
Processing Command-Line Parameters: Accessing positional parameters ($1, $2), getting the script name ($0), the number of arguments ($#), and all arguments ($@).
Parsing Simple Options and Arguments (getopts): Adding basic command-line option support to your scripts.
Understanding Command Exit Status ($?): Checking the success or failure of the last command.
Basic Error Handling: Mentioning set -e as a good practice for exiting on error.
Commenting Your Scripts: Best practices for script clarity and maintainability.
Conditional Logic and Decision Making
Using Command Exit Status in Conditionals.
The test command and the [ ... ] syntax for performing tests.
The [[ ... ]] syntax: Preferred for string and file tests (briefly explain key advantages like safer string comparisons).
File Tests: Testing file properties (-f file exists and is regular, -d directory exists, -e file exists, -r readable, -w writable, -x executable).
Testing Strings and Numbers: Performing comparisons (=, !=, -eq, -ne, -lt, -le, -gt, -ge).
Conditional Statements:
if, elif, else constructs.
The case statement for multiple branch decisions.
The select statement for creating simple interactive menus.
The let command and (( ... )) syntax for performing integer arithmetic.
Controlling Script Execution: The exit statement (ending a script), break and continue statements (controlling loop execution).
Loops and Iteration
Creating Loops:
The for loop (iterating over lists, ranges, command output).
The while loop (looping while a condition is true).
The until loop (looping until a condition is true).
Iterating over file contents.
Organising Code with Functions
When and How to Use Functions: Improving readability and reusability.
Defining and Calling Functions.
Passing arguments to functions and accessing them.
Return values from functions (using return and exit status).
Using local variables within functions.
Script Hygiene and Best Practices
Basic Cleanup: Removing temporary files or resources created by the script.
Using Quotes Effectively: Understanding the difference between double quotes ("...") and single quotes ('...').
Brief mention of ShellCheck: A tool for finding bugs in shell scripts (note it's an external tool).
Optional / Further Topics
Using the trap command for handling signals and script termination.
More Advanced Parameter Expansion techniques.
Associative Arrays.
-
The GNU Bash Reference Manual - https://www.gnu.org/software/bash/manual/
Bash Guide for Beginners - https://tldp.org/LDP/Bash-Beginners-Guide/html/
Advanced Bash-Scripting Guide (More advanced, for later) - https://tldp.org/LDP/abs/html/
ShellCheck (Static analysis tool for shell scripts) - https://www.shellcheck.net/
Trusted by



