Would you like to learn how to read a text file using Bash? In this tutorial, we are going to show you how to use Shell Script to read a line from a text file on a computer running Linux.

• Ubuntu 18
• Ubuntu 19
• Ubuntu 20

Equipment list

Here you can find the list of equipment used to create this tutorial.

This link will also show the software list used to create this tutorial.

Tutorial Linux - Read lines from a file

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

In our example, we create a text file named MYFILE in the TMP directory.

Read from a file using Bash.

Copy to Clipboard

Read lines from a text file using the loop named WHILE.

Copy to Clipboard

There are multiple ways to read lines from a file using Linux.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to read from a text file using Linux.

Tutorial Shell Script - Read lines from a file

Create a text file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

Create a Shell Script to read lines from a file.

Copy to Clipboard

Here is the file content.

Copy to Clipboard

There are multiple ways to read lines from a file using Linux.

Copy to Clipboard

Run the Shell Script.

Copy to Clipboard

Here is the command output.

Copy to Clipboard

Congratulations! You are able to read lines from a file using Shell Script.