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

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:

主站蜘蛛池模板: 特克斯县| 台湾省| 宝鸡市| 博客| 宿松县| 内丘县| 巨野县| 晋州市| 和顺县| 余庆县| 鄂尔多斯市| 琼结县| 衡阳县| 堆龙德庆县| 郓城县| 肥城市| 蒙城县| 东台市| 旌德县| 阿拉善盟| 镇沅| 吉木萨尔县| 清徐县| 漾濞| 大埔区| 县级市| 和林格尔县| 鸡泽县| 隆昌县| 锡林浩特市| 四平市| 榆树市| 香港 | 甘德县| 咸宁市| 旬阳县| 电白县| 武穴市| 丰镇市| 安图县| 郎溪县|