官术网_书友最值得收藏!

Controlling the visibility of entered text

Even though we have limited the input to a single character, we do get to see the text on the screen. In the same way, if we type the name we get to see the entered text before we hit Enter. In this case, it is just untidy but if we were entering sensitive data, such as a pin or a password, we should hide the text. We can use the silent option or -s to achieve this. A simple edit in the script will set this in place:

#!/bin/bash
read -p "May I ask your name: " name
echo "Hello $name"
read -sn1 -p "Press any key to exit"
echo
exit 0

Now, when we use a key to continue, it will not be displayed on the screen. We can see the behavior of the script in the following screenshot:

主站蜘蛛池模板: 景泰县| 泸定县| 铜川市| 二连浩特市| 福安市| 红桥区| 同仁县| 丹江口市| 鹤岗市| 商南县| 宜黄县| 安岳县| 固始县| 车险| 新安县| 阳泉市| 甘南县| 怀来县| 卢氏县| 四川省| 游戏| 福州市| 新丰县| 扶风县| 罗定市| 宜良县| 平泉县| 延安市| 新野县| 沁阳市| 庆云县| 虹口区| 枣阳市| 开化县| 长丰县| 甘肃省| 桐庐县| 从江县| 项城市| 昆明市| 海淀区|