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

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:

主站蜘蛛池模板: 吴桥县| 阜康市| 蚌埠市| 连州市| 肃北| 厦门市| 五大连池市| 连城县| 中超| 广西| 柳州市| 汉阴县| 绵阳市| 紫金县| 西乌珠穆沁旗| 买车| 孟州市| 崇文区| 三都| 孟津县| 彩票| 宜丰县| 新源县| 启东市| 皋兰县| 交城县| 金乡县| 讷河市| 信丰县| 百色市| 大石桥市| 南靖县| 义乌市| 海丰县| 永善县| 平利县| 中超| 札达县| 博客| 安图县| 瓦房店市|