Challenge - 5 Problems
Prompting Pro
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this script?
Consider this bash script snippet that prompts the user for input and then echoes it back:
Bash Scripting
read -p "Enter your name: " name echo "Hello, $name!"
Attempts:
2 left
💡 Hint
The read -p option shows a prompt and stores input in a variable.
✗ Incorrect
The read command with -p shows the prompt and waits for user input, storing it in the variable 'name'. Then echo prints Hello, followed by the input.
💻 Command Output
intermediate2:00remaining
What happens if you run this script?
This script uses read -p but tries to read into two variables:
Bash Scripting
read -p "Enter first and last name: " first last echo "First: $first" echo "Last: $last"
Attempts:
2 left
💡 Hint
read can split input by spaces into multiple variables.
✗ Incorrect
read splits the input by spaces and assigns the first word to 'first' and the second to 'last'.
📝 Syntax
advanced2:00remaining
Which option correctly uses read -p to prompt and store input?
Select the valid bash command that prompts the user and stores input in variable 'age':
Attempts:
2 left
💡 Hint
The -p option must come immediately after read.
✗ Incorrect
Only 'read -p "prompt" variable' is valid syntax. Others cause errors.
🔧 Debug
advanced2:00remaining
Why does this script not show the prompt?
This script tries to prompt the user but the prompt does not appear:
Bash Scripting
read "Enter your city: " city echo "City: $city"
Attempts:
2 left
💡 Hint
Check the syntax for showing a prompt with read.
✗ Incorrect
Without -p, read waits for input but does not show a prompt.
🚀 Application
expert3:00remaining
How to securely prompt for a password without echoing input?
You want to prompt the user for a password using read -p but hide the input as they type. Which command achieves this?
Attempts:
2 left
💡 Hint
Use -s option with read to hide input.
✗ Incorrect
The -s option hides input while typing. It must come with -p for prompt.