Join Scott Simpson for an in-depth discussion in this video Introducing for loops, part of Learning Bash Scripting.
…Now, let's take a look at the for loop.…A for loop sets up a loop based on…particular criteria, usually a sequence or a range of things.…With it, we get a variable that contains the current value with each iteration.…Here's a simple example.…So a for loop looks like this.…It starts with for, and then it has a variable, in this case,…I, that contains the current variable each time that it steps through the list.…Then the word in, and then whatever list of things are unused.…In this case 1, 2, 3.…Then the statement do, followed by anything you want to…do with the current value at that iteration of the loop.…
And then that's all ended with done.…So in this case, this will echo out 1, 2, 3, so let's see that.…And there it is.…So this could get really tedious if we want to use a large…range, say from 1 to 100, so for that we could use brace expansion.…So this will list all the numbers from 1 to 100.…And there it goes.…So already, this syntax has saved me a whole lot of typing.…In bash four and above, I can specify an interval.…
- What is Bash?
- Managing output with grep, awk, and cut
- Understanding Bash script syntax
- Creating a basic Bash script
- Displaying text with "echo"
- Working with numbers, strings, and arrays
- Reading and writing text files
- Working with loops
- Using functions
- Getting user input during execution
- Ensuring a response
Skill Level Beginner
Linux: Bash Shell and Scriptswith Kevin Dankwardt2h 46m Intermediate
1. Working with the Command Line
2. Building Bash Scripts
3. Control Structures
4. Interacting with the User
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.