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

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…

Contents