Skip to content

Instantly share code, notes, and snippets.

@gabrielkfr
Created September 4, 2013 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gabrielkfr/6432038 to your computer and use it in GitHub Desktop.
Save gabrielkfr/6432038 to your computer and use it in GitHub Desktop.
Script demostrativo que detalla la programación necesaria para ocultar con asteriscos la contraseña cuando se la introduce durante la ejecución de un script bash.
#!/bin/bash
#
# SCRIPT DE PRUEBA - LEER CONTRASENIAS
# ====================================
#
# -- Se libera la variable.
unset SECRET_PASSWD
 
# -- Se solicita la introduccion del password y
# se despliega un asterisco por cada character
# introducido por el usuario.
echo
PROMPT="Introduzca su password: "
while IFS= read -p "$PROMPT" -r -s -n 1 char; do
    if [[ $char == $'\0' ]]; then
        break
    fi
    PROMPT='*'
    SECRET_PASSWD+="$char"
done
echo
 
# -- Despliegue del password:
echo
echo "El password introducido fue: $SECRET_PASSWD"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment