Concept Flow - Prompting with read -p
Start Script
Display prompt with read -p
User types input
Input stored in variable
Use input in script
End Script
The script shows a prompt, waits for user input, stores it in a variable, then uses that input.
read -p "Enter your name: " name echo "Hello, $name!"
| Step | Action | Prompt Displayed | User Input | Variable 'name' Value | Output |
|---|---|---|---|---|---|
| 1 | Execute read -p | Enter your name: | |||
| 2 | User types input | Enter your name: | Alice | ||
| 3 | Input stored | Enter your name: | Alice | Alice | |
| 4 | Execute echo | Alice | Hello, Alice! |
| Variable | Start | After read -p | Final |
|---|---|---|---|
| name | "" | "Alice" | "Alice" |
read -p "Prompt" variable - Displays prompt and waits for user input - Stores input in variable - Use variable later with $variable - If no input, variable is empty - Simple way to get user input in bash