0
0
Bash Scriptingscripting~20 mins

read command in Bash Scripting - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Read Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this Bash script using read?
Consider this Bash script that reads user input and prints it back:
Bash Scripting
echo "Enter your name:"; read name; echo "Hello, $name!"
AHello, $name!
BHello, Alice!
CEnter your name:
DHello, !
Attempts:
2 left
💡 Hint
The read command stores input into the variable 'name'.
📝 Syntax
intermediate
2:00remaining
Which option correctly reads two variables from user input in Bash?
You want to read two words from user input into variables 'first' and 'second'. Which command is correct?
Aread first second
Bread -two first second
Cread -f first -s second
Dread first; read second
Attempts:
2 left
💡 Hint
The read command can take multiple variable names separated by spaces.
🔧 Debug
advanced
2:00remaining
Why does this Bash script not store input in the variable?
Script: read name echo "Name is $name"
Bash Scripting
read name
 echo "Name is $name"
ABecause echo does not print variables
BBecause read command is missing the -p option
CBecause variable names cannot be 'name'
DBecause there is a space before echo causing it to run in a subshell
Attempts:
2 left
💡 Hint
Check if the echo command runs in the same shell as read.
🚀 Application
advanced
2:00remaining
How to read a password silently using read in Bash?
You want to read a password from the user without showing it on the screen. Which command achieves this?
Aread -p password
Bread password
Cread -s password
Dread -n password
Attempts:
2 left
💡 Hint
Look for an option that hides input while typing.
🧠 Conceptual
expert
2:00remaining
What happens if you use 'read' inside a pipeline in Bash?
Consider this command: cat file.txt | while read line; do echo "$line"; done What is a common issue with using 'read' inside pipelines?
Bash Scripting
cat file.txt | while read line; do echo "$line"; done
AThe while loop runs in a subshell, so variables set inside are lost after the loop
BThe read command reads the entire file at once
CThe pipeline causes the file to be read twice
DThe read command will fail with a syntax error
Attempts:
2 left
💡 Hint
Think about how pipelines affect shell processes.