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/bash
while read line
do
echo $line
done < 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.