September 2018
Beginner
186 pages
4h 30m
English
We mentioned earlier in this chapter that for loops are often misused to read data line by line from files, or from the output of command pipes. The correct way to do this is with a very common idiom for use with while loops: repeatedly running the read command, always with its -r flag.
Consider a file named fcs, with the names of four famous computer scientists, one on each line:
Ken Thompson Dennis Ritchie John McCarthy Larry Wall
We'd like a program to print out this table, but also to print a link to the person's article on the English-language Wikipedia after each line. There is no dedicated UNIX tool to do this, so we will write our own in Bash.
We might implement a rough version something like this:
#!/bin/bash ...
Read now
Unlock full access