read 隐藏用户输入

  有时会需要脚本用户进行输入,但不希望输入的数据显示在监视器上,典型的例子就是输入密码,当然还有很多其它类型的数据需要隐藏。
-s选项就能够使read命令中输入的数据不现实在监视器上(实际上,数据是显示的,知识read命令将文本颜色设置成了与背景相同的颜色).

文件名: test26.sh 

#!/bin/bash
# hiding input data from the monitor

read -s -p "Enter your passwd:" pass
echo 
echo "Is your password really $pass?"

运行 sh test27.sh 

输出为: Enter your passwd: 

这时你的输入是不会显示的,随便输入mylife,后,显示为: Is your password really mylife? 

原文地址:https://www.cnblogs.com/jacson/p/4791056.html