Recall & Review
beginner
What does the
read -p command do in bash scripting?It displays a prompt message to the user and waits for input, storing the input in a variable.
Click to reveal answer
beginner
How do you store user input into a variable named
name with a prompt "Enter your name:"?Use
read -p "Enter your name: " name to show the prompt and save input in name.Click to reveal answer
intermediate
Can
read -p be used without storing input in a variable?Yes, in which case the input is stored in the special
$REPLY variable.Click to reveal answer
intermediate
What happens if you use
read -p without a space after the prompt string?The prompt message and user input appear together without space, which can confuse the user. Always add a space after the prompt.
Click to reveal answer
beginner
Write a simple bash script snippet that asks for a user's favorite color and then prints it.
read -p "What's your favorite color? " color echo "Your favorite color is $color"
Click to reveal answer
What does the
-p option do in the read command?✗ Incorrect
The
-p option shows a prompt message before waiting for user input.Which command correctly prompts for user input and stores it in variable
age?✗ Incorrect
The correct syntax is
read -p "prompt" variable.What happens if you omit the variable name in
read -p "Enter name:"?✗ Incorrect
If no variable is given, input is stored in the special variable
$REPLY.Why should you add a space at the end of the prompt string in
read -p?✗ Incorrect
Adding a space makes the prompt clear and separates it from the user input.
Which of these is a valid way to prompt for input and print it in bash?
✗ Incorrect
Option A correctly uses
read -p with variable and prints it.Explain how to use
read -p to ask a user for input and save it in a variable.Think about how you show a question and keep the answer.
You got /4 concepts.
Describe common mistakes when using
read -p and how to avoid them.Focus on what can go wrong with the prompt and input storage.
You got /4 concepts.