0
0
Bash Scriptingscripting~5 mins

read command 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 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?
AREPLY
BINPUT
CVAR
DDATA
How do you display a prompt message before reading input?
Aread -r "Message" variable
Bread -m "Message" variable
Cread -p "Message" variable
Dread --prompt "Message" variable
What does read -r do?
AReads input literally without interpreting backslashes
BReads input and removes spaces
CReads input and converts to uppercase
DReads input and waits for a timeout
If you want to read multiple words into separate variables, what does read do?
AStores all input into the first variable only
BReads only the first character
CIgnores extra words after the first
DSplits input by spaces and assigns each word to a variable
What happens if you press Enter without typing anything when read is waiting?
AThe previous value of the variable remains
BThe variable is set to an empty string
CThe script exits immediately
DAn error message appears
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.