From the course: Linux: Bash Shell and Scripts

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Looping with for/while sequences and reading input

Looping with for/while sequences and reading input - Linux Tutorial

From the course: Linux: Bash Shell and Scripts

Start my 1-month free trial

Looping with for/while sequences and reading input

- [Instructor] The read command is handy, because it lets you read input, so your standard input, into variables. And the read command breaks up the input based on white space, so if you say read a b, it will read the first word, the thing up the to first white space, into a. And then b will get the rest of the line. If you read into a b c, a would get the first thing, b would get the second thing, and c would get the rest of the line. It's often handy to combine read with a while loop, so that you can read through a whole file, one line at a time. While loops, uses the word while, and then they have one or more lines of commands. And if the last command successful, I like to say successful instead of true, because it's really a command exits with success or failure. So if the last command is successful, then we do the sequence of commands in between the do and the done. Sometimes this is handy with the operators for expressions, and you can test those sorts of things with the open…

Contents