Hands-on Lab·LPIC-1
Tests, loops, and the options that catch mistakes
Most scripting marks are lost on the test command, not on loops. This guide works through the file and string operators, shows the difference between numeric and string comparison - including a comparison that errored under the capture's shell and what that tells you - and finishes with set -euo pipefail proving its worth against the same script without it.
102: Shells and Scripting Guide 14 of 33 Beginner
- OSUbuntu 26.04 LTS
- Kernel7.0.0-30-generic
- systemd259
- TimeAbout 18 min
| Server Name | IP Address | OS | Roles | CPU | RAM | HDD |
|---|---|---|---|---|---|---|
| LPIC1-A01 | 192.168.0.76 | Ubuntu 26.04 LTS | Debian-family host - dpkg and apt, which objective 102.4 names | 2 Core | 4 GB | 50 GB |
This guide includes
Use this because most scripting marks are lost on the test command rather than on loops. This matters because numeric and string comparison disagree - and one of them errors on input the other accepts quietly.
- using the string and file operators the exam actually asks about
- comparing numerically against comparing as strings, and watching one error
- looping over arguments with spaces in them, with
"$@" - adding the two lines that turn a silent failure loud
Before you start
- variables-scope-and-exit-status
-
The operators the exam actually asks about
-
Numeric against string, and a comparison that errored
-
Loops, and arguments with spaces in them
-
The two lines that turn a silent failure loud