Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Last active January 2, 2016 07:29
Show Gist options
  • Save coderofsalvation/8270449 to your computer and use it in GitHub Desktop.
Save coderofsalvation/8270449 to your computer and use it in GitHub Desktop.
get password bashfunction
# prompts user to enter password
promptpasswd()
{
if [ -n "$1" ]; then
_getpasswd_var_option=$(printf "%s\\n" "$1" | tr '[:upper:]' '[:lower:]')
printf "%s" "Enter your $_getpasswd_var_option password: "
stty -echo
read ${_getpasswd_var_option}passwd
stty echo
printf "\\n"
else
printf "%s" "Enter your password: "
stty -echo
read passwd
stty echo
printf "\\n"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment