Reading files line by line (while read)
📖 Scenario: You have a text file that contains a list of your favorite fruits, one fruit per line. You want to read this file line by line and print each fruit with a friendly message.
🎯 Goal: Build a bash script that reads a file called fruits.txt line by line using while read loop and prints each fruit with the message: "I like <fruit>".
📋 What You'll Learn
Create a file named
fruits.txt with the exact fruits listed.Create a variable to hold the filename.
Use a
while read loop to read the file line by line.Print each fruit with the message: "I like <fruit>".
💡 Why This Matters
🌍 Real World
Reading files line by line is common when processing logs, configuration files, or lists in scripts.
💼 Career
Many automation and system administration tasks require reading files line by line to handle data or perform actions.
Progress0 / 4 steps