Sometimes its required in bash scripts to read a user password. We don't want to echo the password user is entering to the screen. The following shell script accomplishes that
echo -n "Enter password: "
# Save the original stty setting
stty_orig=`stty -g`
# Switch off echoing of password
stty -echo
read password
# Switch things back to normal
stty ${stty_orig}
echo ""
echo "You securely added $password"
echo -n "Enter password: "
# Save the original stty setting
stty_orig=`stty -g`
# Switch off echoing of password
stty -echo
read password
# Switch things back to normal
stty ${stty_orig}
echo ""
echo "You securely added $password"
No comments:
Post a Comment