Challenge - 5 Problems
Read Command Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2: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!"
Attempts:
2 left
💡 Hint
The read command stores input into the variable 'name'.
✗ Incorrect
The script prompts the user, reads input into 'name', then prints 'Hello, ' followed by the input.
📝 Syntax
intermediate2: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?
Attempts:
2 left
💡 Hint
The read command can take multiple variable names separated by spaces.
✗ Incorrect
Option A reads two words from one line of input into 'first' and 'second'. Option A reads two lines separately.
🔧 Debug
advanced2: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"Attempts:
2 left
💡 Hint
Check if the echo command runs in the same shell as read.
✗ Incorrect
A leading space before a command in some shells can cause it to run in a subshell, losing variable values.
🚀 Application
advanced2: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?
Attempts:
2 left
💡 Hint
Look for an option that hides input while typing.
✗ Incorrect
The '-s' option makes read silent, so input is not shown on the screen.
🧠 Conceptual
expert2: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
Attempts:
2 left
💡 Hint
Think about how pipelines affect shell processes.
✗ Incorrect
In many shells, each part of a pipeline runs in a subshell, so variables set inside the loop are lost outside.