diff --git a/Templates/Functions/Read-Sensitive.bash b/Templates/Functions/Read-Sensitive.bash new file mode 100755 index 0000000..7433740 --- /dev/null +++ b/Templates/Functions/Read-Sensitive.bash @@ -0,0 +1,24 @@ +#!/bin/bash + +read_sensitive() { + # Securely read input into a variable + # + # Arguments: + # READVARIABLE + # - 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}" +}