如何在shell中'read -s'?
How to 'read -s' in shell?
我知道可以使用 bash 和 read -s someVar
静默读取用户输入,我想知道是否有 /bin/sh
等价物允许用户输入而不在命令中显示它线?
注意:我只是好奇 /bin/sh
read
是否以某种方式支持此功能。
使用 stty
命令关闭输入字符的回显。
get_entry () {
printf "Choose: "
stty -echo
IFS= read -r choice
stty echo
printf '\n'
}
get_entry
printf "You chose %s\n" "$choice"
我知道可以使用 bash 和 read -s someVar
静默读取用户输入,我想知道是否有 /bin/sh
等价物允许用户输入而不在命令中显示它线?
注意:我只是好奇 /bin/sh
read
是否以某种方式支持此功能。
使用 stty
命令关闭输入字符的回显。
get_entry () {
printf "Choose: "
stty -echo
IFS= read -r choice
stty echo
printf '\n'
}
get_entry
printf "You chose %s\n" "$choice"