Hands-on Lab·Red Hat Certified System Administrator
Shell Loops with for, while and until
One objective, phrased as "process file, command line input" - so the forms that matter are the ones that read a file and the ones that read a command's output. Seven loop forms are run here, and one common mistake is shown failing.
Shell Scripts Guide 63 of 67 Beginner
- OSRHEL 10.0 (Coughlan)
- Kernel6.12.0-55.9.1.el10_0
- dnf4.20.0
- Flatpak1.16.0
- TimeAbout 12 min
- Reviewed23 August 2026
Written against the versions above. `while IFS= read -r LINE` is the correct way to read a file line by line. `IFS=` stops leading and trailing whitespace being stripped and `-r` stops backslashes being interpreted. Without both, a line containing a backslash or indentation comes out altered.
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| RHCSA-A01 | 192.168.0.31 | RHEL 10.0 (Coughlan) | Practice node (graded) - spare /dev/sda | 2 Core | 4 GB | 50 GB + 15 GB |
Before you start
- A shell.
- The session writes and removes
~/scripts.
-
Seven forms, run
-
Why `{1..$TOP}` does not work