脚本:
-
#!/bin/bash
-
echo -e "input the password:"
-
stty -echo
-
read password
-
stty echo
-
echo "the password read success and exit..."
运行脚本:
此时输入密码不会显示其内容;
下面单独看一下stty -echo 和stty echo的效果:
命令行下输入
stty -echo:

此后无论输入什么都不会显示,但是依然会执行!
接着在不显示的情况下输入stty echo:

输入的内容又显示了!
可见,其原理是:
-echo禁止将输出发送到终端,而echo则允许发送输出;
还有一个方法也可以实现该功能,那就是使用read的-s参数:

还可以一边显示提示信息一边隐藏输入:

这两个命令可以用在输入一些重要内容时将其隐藏,一定程度上保证了安全性,还是挺实用的!
阅读(988) | 评论(0) | 转发(0) |