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

推薦閱讀
- Data Visualization with D3 4.x Cookbook(Second Edition)
- Mastering Adobe Captivate 2017(Fourth Edition)
- 劍指JVM:虛擬機實踐與性能調優(yōu)
- Windows系統(tǒng)管理與服務配置
- 數據結構習題精解(C語言實現(xiàn)+微課視頻)
- Java零基礎實戰(zhàn)
- 細說Python編程:從入門到科學計算
- 機器學習微積分一本通(Python版)
- Nagios Core Administration Cookbook(Second Edition)
- Python數據可視化之美:專業(yè)圖表繪制指南(全彩)
- Delphi開發(fā)典型模塊大全(修訂版)
- Python編程入門(第3版)
- Learning TypeScript
- Distributed Computing with Python
- Spring Microservices