Bash_Scripts/Templates/Functions/Read-Sensitive.bash
2021-08-17 20:22:22 -05:00

25 lines
468 B
Bash
Executable File

#!/bin/bash
read_sensitive() {
# Securely read input into a variable
#
# Arguments:
# READVARIABLE <type: variable> <position: 1> <required: true>
# - A variable must be passed and the output of this function will be set to that variable
# e.g: read_sensitive MYVAR
#
# Usage:
# read_sensitive SOMEVAR
#
# POSIX Compliant:
# Yes
#
stty -echo
local INPUT
read -r INPUT
stty echo
printf "\n"
eval "${1}=${INPUT}"
}