接收输入:read -p "Please Input the key:" key
不显示输入内容:read -s
升级处理:将输入显示为星号
echo -e "Please Input the key:\c"
x=0
while : ;do
char=`
stty cbreak -echo
dd if=/dev/tty bs=1 count=1 2>/dev/null
stty -cbreak echo
`
if [ "$char" = "" ];then
break
fi
if [[ "$ret" == $(echo -ne '\b') ]];then
if [ $x -eq 0 ];then
continue
fi
enc_key="${enc_key%?}"
printf "33[1D"
printf "33[K"
let x--
continue
fi
enc_key="$enc_key$char"
echo -n "*"
let x++
done
echo #换行
参考:https://blog.csdn.net/ztguang/article/details/51404096