Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SHELL

password with asterisk in bash script

#!/bin/bash

password=""
echo "Enter Username : "

# it will read username
read username
pass_var="Enter Password :"

# this will take password letter by letter
while IFS= read -p "$pass_var" -r -s -n 1 letter
do
    # if you press enter then the condition 
    # is true and it exit the loop
    if [[ $letter == $'' ]]
    then
        break
    fi
    
    # the letter will store in password variable
    password=password+"$letter"
    
    # in place of password the asterisk (*) 
    # will printed
    pass_var="*"
done
echo
echo "Your password is read with asterisk (*)."
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #password #asterisk #bash #script
ADD COMMENT
Topic
Name
7+6 =