Press "Enter" to skip to content

Linux/Unix: Read a File Line by Line Using Bash Shell Script

Here I am giving an example of a Linux program to read a file line by line using the bash shell script.

Read a File Line by Line Using Shell Script

The following shell script will prompt the user to enter a file name and then it will read the file content line by line using the while loop and will assign each line into a variable and then it will print on the screen.

echo "Enter the name of file:"
read filename
while read var_line
echo $var_line


$ ./
Enter the name of file:
this is first line.
this is second line.
this is third line.

See also:

Vinish Kapoor

Hi, I am a full stack developer and writing about development. I document everything I learn and help thousands of people. is created, written, and maintained by me; it is built on WordPress, and hosted by Bluehost. Connect with me on Facebook, Twitter, GitHub, and get notifications for new posts.

Comments are closed.