From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Unlock this course with a free trial
Join today to access over 24,900 courses taught by industry experts.
Looping with for, the seq command, and backticks - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Looping with for, the seq command, and backticks
- [Instructor] Let's look at some more advanced and, as it turns out, more useful techniques that you might want to use with loops. For example, the seq command, S-E-Q, will generate a sequence of numeric values. You say seq 1 5, it's going to echo out 1, 2, 3, 4, 5, so you can start out at a different number and with a different number and so forth. You can use that in a for loop, but in a for loop, you got to get the output of the seq command onto the command line. You can't pipe it into a for loop. If you pipe into a for loop, that doesn't make sense. You could pipe into a while loop, but then you have to use the read command. When you have a way to generate the list of things you want to iterate over in a for loop, then you put the command to generate the list in backticks. Those are not apostrophes; those are backwards-leaning ticks. Those are sometimes up underneath the Escape key way over on the left. Maybe it's with the little wavy bar, the tilde. It's not a quote, so if I do…
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
-
-
-
-
The typeset and declare commands for variables and arrays5m 59s
-
(Locked)
Looping with while sequences and reading input6m 12s
-
(Locked)
Looping with for, the seq command, and backticks8m 3s
-
(Locked)
Defining functions and using return and exit4m 17s
-
(Locked)
Using file descriptors, file redirection, and pipes7m 23s
-
(Locked)
Here documents3m 54s
-
(Locked)
Open and close file descriptors5m 22s
-
(Locked)
Control-flow if-then-else with the test command4m 42s
-
(Locked)
Case statements3m 45s
-
(Locked)
Using arithmetic operators3m 26s
-
(Locked)
Challenge: Variables in functions, loops, and arithmetic2m 46s
-
(Locked)
Solution: Variables in functions, loops, and arithmetic2m 42s
-
-
-
-