Reading files

The read command is not only used to read inputs from the user; you can use the read command to read files for further processing.

#!/bin/bashwhile read linedoecho $linedone < yourfile.txt

We redirect the file content to the while command to read the content using the read command, line by line.

Finally, we print the line using the echo command.

Get Mastering Linux Shell Scripting now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.