0
0
Bash Scriptingscripting~5 mins

Reading into multiple variables in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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"?
AStores 'hello' in a and 'world' in b
BStores 'hello world' in a and leaves b empty
CStores 'hello' in b and 'world' in a
DThrows an error because of two variables
If you run read x y and input "one two three", what will be stored in y?
A"two"
B"three"
C"two three"
DEmpty string
How do you show a prompt message before reading input in bash?
Aecho "Enter: " read var
Binput -p "Enter: " var
Cprompt "Enter: " var
Dread -p "Enter: " var
What happens if you use read with only one variable and input multiple words?
AOnly the first word is stored
BAll words are stored as one string
CAn error occurs
DThe input is ignored
Which command reads three words into variables a, b, and c?
Aread a b c
Bread abc
Cread -3 a b c
Dread -abc
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.