Challenge - 5 Problems
Interactive Script 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?
Consider this Bash script that reads user input and prints a greeting. What will it output if the user types Alex and presses Enter?
Bash Scripting
echo "Enter your name:"; read name; echo "Hello, $name!"
Attempts:
2 left
💡 Hint
Think about what the script prints before and after reading input.
✗ Incorrect
The script first prints the prompt 'Enter your name:', then waits for input. After the user types 'Alex', it prints 'Hello, Alex!'.
🧠 Conceptual
intermediate1:30remaining
Why does using 'read' make a Bash script interactive?
Select the best explanation for why the 'read' command makes a Bash script interactive.
Attempts:
2 left
💡 Hint
Think about what happens when the script stops and waits.
✗ Incorrect
'read' stops the script execution and waits for the user to type something, making the script interactive.
🔧 Debug
advanced2:30remaining
Why does this script not wait for input?
This script is supposed to ask for a name and greet the user, but it immediately prints 'Hello, !' without waiting. What is the problem?
Bash Scripting
echo "Enter your name:"; name=$read; echo "Hello, $name!"
Attempts:
2 left
💡 Hint
Check how the script tries to get input into the variable.
✗ Incorrect
Using 'name=$read' assigns the empty value of the unset variable 'read' to 'name' instead of executing the 'read' command. The correct way is to use 'read name' to pause and get input.
🚀 Application
advanced3:00remaining
How to make a script ask multiple questions interactively?
You want a Bash script to ask the user for their first name and last name separately, then greet them. Which script correctly does this?
Attempts:
2 left
💡 Hint
Think about how to ask questions one by one and store answers separately.
✗ Incorrect
Option D asks for first and last names separately with two 'read' commands, then prints the full greeting.
📝 Syntax
expert2:00remaining
What error does this script produce?
What error will this Bash script produce when run?
Bash Scripting
echo "Enter your age:"; readage; echo "You are $age years old."
Attempts:
2 left
💡 Hint
Look carefully at the command used to read input.
✗ Incorrect
The script tries to run 'readage' as a command, which does not exist, causing a 'command not found' error.