Recall & Review
beginner
What does the
read command do in bash scripting?The
read command takes input from the user or a file and stores it into one or more variables.Click to reveal answer
beginner
How do you read multiple values into separate variables in bash?
Use
read var1 var2 var3. Each word from the input is assigned to a variable in order.Click to reveal answer
intermediate
What happens if the input has more words than variables when using
read?The last variable gets all remaining words as a single string.
Click to reveal answer
beginner
How can you prompt the user with a message before reading input into variables?
Use
read -p "Your message: " var1 var2 to show a prompt before input.Click to reveal answer
beginner
Why is reading into multiple variables useful in scripting?
It lets you capture several pieces of related input at once, like a first and last name, making scripts interactive and flexible.
Click to reveal answer
What does the command
read a b do when you enter: "hello world"?✗ Incorrect
The first word goes to the first variable, the second word to the second variable.
If you run
read x y and input "one two three", what will be stored in y?✗ Incorrect
The last variable gets all remaining words after the first variable.
How do you show a prompt message before reading input in bash?
✗ Incorrect
The
-p option with read shows a prompt.What happens if you use
read with only one variable and input multiple words?✗ Incorrect
All input words go into the single variable as one string.
Which command reads three words into variables a, b, and c?
✗ Incorrect
Listing variables separated by spaces after
read assigns input words accordingly.Explain how the
read command assigns input words to multiple variables in bash.Think about how words from a sentence are given to each variable.
You got /3 concepts.
Describe a simple script that asks for a user's first and last name and stores them in two variables.
Use read -p to show a message and read two variables.
You got /4 concepts.