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 while sequences and reading input - Linux Tutorial
From the course: Linux Bash Shells and Scripts: Streamlining Tasks and Enhancing Workflows with Automation
Looping with while sequences and reading input
- [Instructor] All right, now we're getting into even more cool stuff with Bash. Let's talk about the read command. Read reads from the keyboard, typically, or you could redirect from a file, and so forth. But read, and then you give it some variables, and it'll take the current line and put the values of the line into those variables. And read has the idea of words, stuff separated by spaces, for example. So if you give two variables, say read a b, the first word will go into a, and then the rest of the line will go into b. And I find reed is pretty handy, pretty convenient in for loops, for example. And then read returns failure, or essentially end of file, at the end of a file. So if it's in a while loop, when you run out of stuff for read, then the while loop will complete. Let's look at while loops. You have the word, while, and you have some list of commands. Oftentimes, it's just one line of commands. And while we'll run that command, and if it's successful, you'll do the…
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
-
-
-
-