Module Title: dgt_bash03 – Variables
Module Description:
The module “dgt_bash03 – Variables” covers variables in Bash scripting. Variables are used in every script that automates or customizes work on Unix-like systems, so understanding them properly is essential for anyone who has to read, trust and maintain automation.
In this module the theory is studied carefully, and the practice is done strictly in natural language. You will not write the scripts yourself: you will explain to the machine what the script must do (“read the target directory from the first argument, default to /var/log, and export it for the child process”), then read the script it produces line by line, checking quoting, scope and exports against what you learned, and ask for corrections until it is right.
Module Objectives:
- Understand the fundamental concepts of variables within Bash.
- Know how variables of different types are declared, assigned and used, well enough to recognise correct and incorrect usage in a script the machine writes.
- Explore variable scope and lifetime, so that you can spot the common scripting pitfalls they cause in generated code.
- Describe precise requirements to the machine and verify, with real-world examples, that the variables it declares behave as intended.
Key Topics Covered:
- Introduction to Variables in Bash
- What are variables?
-
Why use variables in scripts?
-
Basic Variable Declaration and Assignment
- Simple assignment syntax
-
Best practices for naming variables
-
Examples of Variable Declaration
- Integer and string variable declarations
- Reading input from users via command line or script arguments
-
Exporting variables for child processes
-
Advanced Variable Manipulation
- Using special variables e.g.,
$?,$$,$@ - String manipulation techniques
-
Array variables and their operations
-
Variable Scope and Lifetime
- Understanding local vs global scope
- Function-local variables
-
Environment variables and their persistence
-
Practical Use Cases and Examples
- Case studies in which the machine writes automation scripts from your description and you review how they use variables
-
Real-world examples showing how variables are used
-
Common Pitfalls and How to Avoid Them
- Common errors in variable declaration and usage, and how to catch them in generated scripts
- Guiding the machine through debugging scripts that involve variables
Target Audience:
This module is intended for system administrators, DevOps engineers, software developers, or any IT professionals who want to understand Bash scripts well enough to direct and review automation. No prior experience with shell scripting is required; however, a basic understanding of how the command line works will be beneficial.
By the end of this module, participants will understand how variables work in Bash and will be able to instruct the machine to build automation that uses them correctly, and to verify that it really does what was asked.
The students can push their exercises to the Academy DevOps & SRE Git project. For this module, create a folder with your username as its name in the following subfolder: https://github.com/Garanti-Del-Talento/gdt_academy
