Shell Line Input
In the previous chapters, we learned how to process files line by line using predefined commands such as cut
or tr
. However, we are often limited by the fact that one command can do only one operation at a time. The shell provides some facilities to allow processing a file or typed input line by line. Some of these are discussed in the following section.
Line Input Commands
These commands allow us to write scripts that work with input data line by line and process it.
The read Command
The shell provides the read
command to process input in a line-by-line fashion. This command has two main uses:
- To read input from the user interactively from scripts
- To read input from a file and process it
The read
command accepts any number of variable names as arguments. When executed, it attempts to read text from its stdin
and assign the input to the variables. For example, look at the following snippet:
robin ~ $ read COLOR THING red apple robin...