bash内置read
有一个标志-s
,可以阻止它回显从命令行读取的任何内容。在搜索opengroup.org和过滤了read
的所有其他含义之后,我仍然没有找到一个POSIX/便携的等价物。有什么合理的方法吗?
在bash中,这很容易:
$ bash -c 'read -sp "What is your password? " password; printf "\n%s\n" "$password"'
What is your password?
I'll never tell!
但在sh…中
$ dash -c 'printf "What is your password? "; read password >/dev/null 2>&1; printf "\n%s\n" "$password"'
What is your password? I'll never tell!
I'll never tell!
发布于 2014-07-30 17:16:04
因此,您的问题的答案是,正如这个链接中所描述的,您可以使用内置命令stty关闭
stty -echo
ps:
别忘了保存以前的设置
old_set=$(stty -g)
stty -echo
read -r password
stty "$old_set"
https://stackoverflow.com/questions/25038184
复制相似问题