Bird
0
0

How can you modify this script to ensure the password input is not displayed and the prompt appears on a new line?

hard🚀 Application Q9 of 15
Bash Scripting - User Input
How can you modify this script to ensure the password input is not displayed and the prompt appears on a new line?
read -p "Enter password: " -s password
echo "Password saved"
ANo change needed; script is correct
BChange to <code>read -s -p "Enter password: " password; echo</code>
CUse <code>read -p "Enter password: " password -s</code>
DAdd <code>echo -n</code> before read command
Step-by-Step Solution
Solution:
  1. Step 1: Fix option order for silent input

    Options -s and -p must come before variable name; Change to read -s -p "Enter password: " password; echo does this.
  2. Step 2: Add echo to move to new line after silent input

    Because -s hides input and prompt stays on same line, adding echo prints a newline.
  3. Final Answer:

    Change to read -s -p "Enter password: " password; echo -> Option B
  4. Quick Check:

    Correct option order and newline after input [OK]
Quick Trick: Add echo after read -s -p to move to new line [OK]
Common Mistakes:
MISTAKES
  • Placing options after variable
  • Not adding newline after silent input
  • Misusing echo -n before read

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes