0
0
Bash Scriptingscripting~20 mins

Why input makes scripts interactive in Bash Scripting - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Interactive Script 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?
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!"
A
Enter your name:
Hello, Alex!
BEnter your name:
CHello, Alex!
DHello, $name!
Attempts:
2 left
💡 Hint
Think about what the script prints before and after reading input.
🧠 Conceptual
intermediate
1:30remaining
Why does using 'read' make a Bash script interactive?
Select the best explanation for why the 'read' command makes a Bash script interactive.
A'read' prints output without waiting for input.
B'read' automatically fills variables without user action.
C'read' pauses the script and waits for user input from the keyboard.
D'read' runs commands in the background without interaction.
Attempts:
2 left
💡 Hint
Think about what happens when the script stops and waits.
🔧 Debug
advanced
2: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!"
AThe variable assignment uses '$read' instead of the 'read' command.
BThe script needs 'read -p' to prompt and read in one step.
CThe 'echo' command is missing quotes around the prompt.
DThe variable 'name' is not declared before use.
Attempts:
2 left
💡 Hint
Check how the script tries to get input into the variable.
🚀 Application
advanced
3: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?
Aecho "First name:"; read first last; echo "Hello, $first $last!"
Bread first last; echo "Hello, $first $last!"
Cecho "Enter full name:"; read name; echo "Hello, $name!"
Decho "First name:"; read first; echo "Last name:"; read last; echo "Hello, $first $last!"
Attempts:
2 left
💡 Hint
Think about how to ask questions one by one and store answers separately.
📝 Syntax
expert
2: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."
ASyntax error near unexpected token `readage`
Bbash: readage: command not found
CYou are years old.
DNo error, script runs fine
Attempts:
2 left
💡 Hint
Look carefully at the command used to read input.