From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)
Unlock the full course today
Join today to access over 22,400 courses taught by industry experts or purchase this course individually.
Iterate with for loops - Linux Tutorial
From the course: Cert Prep LPIC-1 Exam 102 (Version 5.0)
Iterate with for loops
- [Narrator] Whenever you want to loop through a finite list of items, you may want to use a for loop. The syntax for the for loop looks like this. We start with a list of items to loop through, as we iterate through them, they're assigned to a variable. In this example, the variables name is item. Inside the loop, we do something with the contents of the variable. The list for the for loop can come from any number of sources. It can be a static list that we create such as one, two, three, four, five, or a list of names. If your looking for a list of sequential numbers, we can create a dynamically. In the past, we'd use a sequence command for this. And we'd use command substitution to get it to run. However, it's better to have Bash create the list using expansion. This way we're not spawning a new shell and executing commands. It's more reliable and it's faster. There are times though when we will use command…
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
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-