6. Variables, Expansion, and Arrays#
This chapter separates Bash data handling from general syntax: variables, parameters, expansion, command substitution, indexed arrays, and associative arrays used for counting and reporting.
Variables: Store shell values safely.
Expansion: Control when Bash substitutes values.
Parameters: Handle script and function inputs.
Arrays: Collect related values for automation.
Security: Avoid leaking secrets through environment, history, and PATH behavior.
Chapter Video
Associative Arrays in Bash (AKA Key-Value Dictionaries) (15:06) by Nick Janetakis
Hosted on YouTube; property of its original creator, embedded here for educational reference only.
Learning Objectives
By the end of this chapter, you will be able to:
Assign and expand shell variables safely.
Use positional parameters and command substitution deliberately.
Apply parameter expansion to validate and transform values.
Use indexed and associative arrays for scripts that count or group events.
Explain common secret-leak and PATH-hijacking risks.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Variable |
A named shell value. |
2 |
Expansion |
The shell step that substitutes values or filenames. |
3 |
Parameter |
A named, positional, or special shell value. |
4 |
Environment variable |
A variable inherited by child processes. |
5 |
Command substitution |
The |
6 |
Parameter expansion |
The |
7 |
Positional parameter |
A script argument such as |
8 |
Indexed array |
An array addressed by numbers. |
9 |
Associative array |
An array addressed by string keys. |
10 |
PATH hijacking |
Running an unintended command because lookup order was manipulated. |