Challenge - 5 Problems
Silent Input Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate1:30remaining
What is the output of this silent input script?
Consider this Bash script snippet that asks for a password silently and then prints a confirmation message.
What will be the output if the user types "mypassword" when prompted?
What will be the output if the user types "mypassword" when prompted?
Bash Scripting
read -s -p "Enter password: " pass echo "Password length is ${#pass}"
Attempts:
2 left
💡 Hint
The -s option hides the input, so the typed password won't appear on screen.
✗ Incorrect
The read command with -s hides the input, so the typed password does not show. The prompt appears, but the typed characters are not echoed. The echo prints the length of the password entered, which is 10 for "mypassword".
📝 Syntax
intermediate1:00remaining
Which option correctly reads a password silently and stores it in variable 'pw'?
Select the correct Bash command to read a password silently into variable 'pw' with a prompt "Password:".
Attempts:
2 left
💡 Hint
The order of options matters; -s and -p come before the variable name.
✗ Incorrect
The correct syntax is 'read -s -p "Password:" pw'. Options -s and -p must come before the variable name. Option A has wrong order, C places variable before options, D misses variable name.
🔧 Debug
advanced1:30remaining
Why does this script show the password when typed?
This script is intended to read a password silently but shows the typed password on screen.
Identify the reason for this behavior.
Script:
read -p "Enter password: " -s password echo "Password entered."
Identify the reason for this behavior.
Script:
read -p "Enter password: " -s password echo "Password entered."
Attempts:
2 left
💡 Hint
Check the order of options in the read command.
✗ Incorrect
In Bash, the order of options matters. The -s option must come before -p. Here, -p comes first, so -s is ignored and input is echoed.
🚀 Application
advanced2:00remaining
How to confirm password input matches silently?
You want to ask the user to enter a password twice silently and check if both entries match.
Which script snippet correctly implements this?
Which script snippet correctly implements this?
Attempts:
2 left
💡 Hint
Use double brackets [[ ]] and quote variables to avoid errors.
✗ Incorrect
Option B correctly uses -s before -p, prints newlines after silent input, uses [[ ]] with quoted variables for string comparison. Others have syntax or quoting issues.
🧠 Conceptual
expert1:30remaining
What happens if you use 'read -s' without '-p' in a script?
In a Bash script, you use 'read -s password' without the -p option.
What will the user experience and what must you do to make the input clear?
What will the user experience and what must you do to make the input clear?
Attempts:
2 left
💡 Hint
Think about user experience when no prompt is shown.
✗ Incorrect
Using 'read -s password' hides input but shows no prompt, so user types blindly. To guide user, script should print a prompt before calling read.