is possible store - example user input - variable in bash? have script reads password...
#!/bin/bash while [ $# -gt 0 ]; key="$1"; case $key in -p|--prompt) if [ ! "$2" ]; printf "\e31;1mmust pass in prompt\e[0m\n"; exit 1; fi printf "$2"; shift 2; ;; esac done psswd=; c=; while [ "$c" != "^m" ]; read -n 1 -s c; if [ "$c" == "^?" ]; if [ ${#psswd} -gt 0 ]; psswd=${psswd:: -1}; printf "\b \b"; fi elif [ ! "$c" ]; # pressed enter break; else psswd="$psswd$c"; printf "*"; fi done; printf "\nyour entered password is: $psswd\n" (sorry, ^m newline , ^? backspace. meaning can't copy , paste, how shows in vim, , don't know how else write it.)
... , password strored variable. know how read stores variable. if read can it, why can't i? have ideas?
(or perhaps there better way store password... echo "$psswd" | base64 > .pass - isn't want do.)
update
basically, how psswd variable outside shell? or how access password once shell closed? there better way store other variable?
as rojomoke suggests, enough:
read -p "enter password: " -s pw echo "you entered: $pw" if this: read -n 1 -s c , hit enter, $c empty, not hold \r; , if hit backspace, in testing, $c holds character octal value 177
read -n 1 -s c printf "%s" "$c" | od -c
Comments
Post a Comment