From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Iterate with while loops - Linux Tutorial
From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)
Iterate with while loops
- [Instructor] The for loop is designed to loop through a finite number of items and when it gets to the end, it exits. It is possible to have a condition inside the for loop that will break out of the loop even before it runs out of items. A better idea is to use a loop with a condition built in. For this we have the while loop and until loops. The only difference is that the while loop will iterate while a condition is true and the until loop will iterate until the condition is true. I usually use a while loop over the until loop. Let's take a look at the syntax of the while loop. The condition inside the single square brackets follows the same rules as an if conditional inside of single square brackets, which means you can match on wildcards, but not regular expressions. The simplest while loop we can make is the infinite loop by replacing the condition with the word true. This loop will keep iterating forever, unless…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
Introduction to Bash2m 9s
-
What is a shell script?3m 57s
-
Execute compound commands5m 59s
-
Use Command and Variable substitution6m 21s
-
Conditional flow with if, then if3m 12s
-
Conditional flow with case2m 21s
-
Iterate with for loops2m 42s
-
Iterate with while loops1m 30s
-
Using return codes6m 32s
-
Create a monitor script3m
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-