I currently use the command-line utility security
in a shell script to access a password from keychain. I am surprised that echoing my password variable works and reveals the password in my terminal window.
I used the function get_pw suggested here and then simply assign the password to a variable PASSWORD. Is it possible to make terminal hide the password?
My shell script looks as follows:
ACCOUNT_NAME='MyAccountName'
get_pw() {
security 2>&1 >/dev/null find-generic-password -ga $ACCOUNT_NAME \
| ruby -e 'print $1 if STDIN.gets =~ /^password: "(.*)"$/'
}
PASSWORD=$(get_pw)
Then when writing echo $PASSWORD, the password is revealed.
PASSWORD=$(get_pw ...)
and see the password also in Terminal? If yes, please add your definition ofget_pw
to the question. If no, please add the commands you use.