Prompting User Input with read -p in Bash
📖 Scenario: You are creating a simple script that asks a user for their favorite fruit and then shows a message with their answer.
🎯 Goal: Build a Bash script that prompts the user to enter their favorite fruit using read -p and then prints a message including their input.
📋 What You'll Learn
Use
read -p to prompt the user with the exact text: "Enter your favorite fruit: "Store the user input in a variable called
fruitPrint the message: "Your favorite fruit is: <fruit>" where <fruit> is the user input
💡 Why This Matters
🌍 Real World
Scripts often need to ask users for information like names, choices, or passwords. Using <code>read -p</code> makes this easy and interactive.
💼 Career
Knowing how to prompt users in shell scripts is useful for system administrators, DevOps engineers, and anyone automating tasks on Linux or Unix systems.
Progress0 / 4 steps