- 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:

推薦閱讀
- Testing with JUnit
- 用戶體驗增長:數字化·智能化·綠色化
- Mastering openFrameworks:Creative Coding Demystified
- ServiceNow:Building Powerful Workflows
- HTML+CSS+JavaScript編程入門指南(全2冊)
- RocketMQ實戰與原理解析
- 大學計算機基礎實驗指導
- Mastering jQuery Mobile
- Learning Grunt
- Xamarin Cross-Platform Development Cookbook
- Python第三方庫開發應用實戰
- C#程序開發參考手冊
- 零基礎入門學習C語言:帶你學C帶你飛
- Comprehensive Ruby Programming
- Web 2.0策略指南