shell script password snippet
Date: November 5, 2010
i was writing a script and needed to hide input for a password.
here is the snippet:
echo -n "please enter password and press [enter]: " STTY_ORIG=`stty -g` stty -icanon -echo KEY=$(dd bs=1 count=1 2>/dev/null) while [ x$KEY != x$(echo) ]; do PASSWORD=$PASSWORD$KEY echo -n \* KEY=$(dd bs=1 count=1 2>/dev/null) done echo stty $STTY_ORIG # test password to make sure it works echo $PASSWORD
there is almost definitely an easier way of doing this but this was done quick.
Leave a Reply