8. Control Flow#
This chapter turns expressions into script structure: branches, cases, loops, loop control, interactive input, and command-line arguments.
Branching: Use
if,elif,else, andcaseto choose among actions.Loops: Repeat commands with
for,while, anduntil.Loop control: Use
breakandcontinueto leave or skip loop iterations.Input: Read values from users and scripts without losing quoting safety.
Arguments: Use positional parameters to make scripts reusable.
Chapter Video
How To Write Bash Scripts In Linux - Complete Guide (Part 9 - For Loops) (12:32) by Learn Linux TV
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:
Write
if,elif,else, andcasebranches.Use
for,while, anduntilloops for repetition.Control loops with
breakandcontinue.Read user input and process script arguments.
Chapter Flow
Glossary
# |
Term |
Explanation |
|---|---|---|
1 |
Control flow |
The order in which a script chooses and repeats commands. |
2 |
Branch |
A path of execution selected by a condition. |
3 |
|
A conditional structure that runs commands when a test succeeds. |
4 |
|
An additional conditional branch checked after an earlier |
5 |
|
The fallback branch when no prior condition succeeds. |
6 |
|
A branching structure that matches a value against patterns. |
7 |
Pattern |
A shell matching expression used by |
8 |
|
A loop that iterates over a list of words or values. |
9 |
|
A loop that repeats while a command or test succeeds. |
10 |
|
A loop that repeats until a command or test succeeds. |
11 |
Loop variable |
A variable assigned a new value during each loop iteration. |
12 |
|
A command that exits the current loop. |
13 |
|
A command that skips to the next loop iteration. |
14 |
Nested loop |
A loop placed inside another loop. |
15 |
|
A Bash builtin that reads input into variables. |
16 |
Prompt |
Text shown to request user input. |
17 |
Positional argument |
A command-line argument available as |
18 |
|
A command that moves positional parameters left. |
19 |
Input validation |
Checking user or file input before using it. |
20 |
Script interface |
The arguments, prompts, and outputs through which users interact with a script. |