Recall & Review
beginner
What does the
read command do in Bash scripting?The
read command waits for user input from the keyboard and stores it in a variable.Click to reveal answer
beginner
How do you store user input into a variable named
name using read?Use
read name. This waits for input and saves it in the variable name.Click to reveal answer
intermediate
What happens if you use
read without specifying a variable?The input is stored in the default variable
REPLY.Click to reveal answer
beginner
How can you prompt the user with a message before reading input?
Use the
-p option like read -p "Enter your name: " name to show a prompt.Click to reveal answer
intermediate
What does the
-r option do in the read command?It prevents backslashes from being treated as escape characters, so input is read literally.
Click to reveal answer
Which variable holds input if you run
read without a variable name?✗ Incorrect
When no variable is given,
read stores input in the special variable REPLY.How do you display a prompt message before reading input?
✗ Incorrect
The
-p option shows a prompt message before waiting for input.What does
read -r do?✗ Incorrect
The
-r option disables backslash escaping, so input is read exactly as typed.If you want to read multiple words into separate variables, what does
read do?✗ Incorrect
When multiple variables are given,
read splits input by spaces and assigns each word to a variable.What happens if you press Enter without typing anything when
read is waiting?✗ Incorrect
Pressing Enter without input sets the variable to an empty string.
Explain how the
read command works in Bash scripting and how to use it to get user input.Think about how you ask a friend a question and wait for their answer.
You got /4 concepts.
Describe the purpose of the
-r option in the read command and when you might need it.Imagine typing a file path with backslashes and wanting it exactly as typed.
You got /3 concepts.