Function to read sensitive info from terminal
This commit is contained in:
parent
0c7dfd1dd3
commit
84a74edd9e
24
Templates/Functions/Read-Sensitive.bash
Executable file
24
Templates/Functions/Read-Sensitive.bash
Executable file
@ -0,0 +1,24 @@
|
|||||||
|
#!/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}"
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user