- Mastering Linux Shell Scripting
- Andrew Mallett
- 147字
- 2021-07-30 09:40:46
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:

推薦閱讀
- Google Flutter Mobile Development Quick Start Guide
- Java Web基礎與實例教程(第2版·微課版)
- Python程序設計(第3版)
- Android Application Development Cookbook(Second Edition)
- JavaScript前端開發與實例教程(微課視頻版)
- Scratch真好玩:教小孩學編程
- Android程序設計基礎
- 用戶體驗可視化指南
- 計算機應用基礎教程(Windows 7+Office 2010)
- Spring Boot實戰
- 軟件測試綜合技術
- Qlik Sense? Cookbook
- Illustrator CS6設計與應用任務教程
- Clojure Polymorphism
- Unity Android Game Development by Example Beginner's Guide