0
0
Bash Scriptingscripting~10 mins

Silent input with read -s (passwords) in Bash Scripting - Mini Project: Build & Apply

Choose your learning style9 modes available
Silent input with read -s (passwords)
📖 Scenario: You are creating a simple script to ask a user for their username and password. For security, the password should not be shown on the screen as the user types it.
🎯 Goal: Build a bash script that asks for a username and a password. The password input should be silent (hidden) using read -s. Then display a message showing the username and a confirmation that the password was received.
📋 What You'll Learn
Create a variable username to store the user's input.
Create a variable password to store the user's input silently using read -s.
Print a message showing the username and a confirmation that the password was entered.
💡 Why This Matters
🌍 Real World
Scripts often need to ask users for passwords without showing them on screen to keep them safe.
💼 Career
Knowing how to securely get passwords in scripts is important for system administrators and developers automating tasks.
Progress0 / 4 steps
1
DATA SETUP: Ask for the username
Write a line to ask the user to enter their username and store it in a variable called username using read.
Bash Scripting
Need a hint?

Use read -p "Enter your username: " username to prompt and save input.

2
CONFIGURATION: Prepare to read password silently
Write a line to prompt the user to enter their password silently and save it in a variable called password using read -s.
Bash Scripting
Need a hint?

Use read -s -p "Enter your password: " password to read password silently.

3
CORE LOGIC: Add a newline after password input
Add a line to print a newline after the silent password input so the next output appears on a new line.
Bash Scripting
Need a hint?

Use echo with no arguments to print a newline.

4
OUTPUT: Display username and password confirmation
Write a line to print: Username: [username] and Password received. using echo and the variable username.
Bash Scripting
Need a hint?

Use echo "Username: $username" and echo "Password received." to show output.