当前位置:网站首页>Shell tips (134) simple keyboard input recorder
Shell tips (134) simple keyboard input recorder
2022-06-25 07:35:00 【Music master】
Realization effect :
Run script , prompt 4 Characters .
In the input process , Not up to 4 Five characters before display .
Enter the first 4 After characters , Automatically display the entered 4 Characters .
#!/bin/bash
keypresses=4
old_tty_setting=$(stty -g)
echo "Presss $keypresses keys"
stty -icanon -echo
keys=$(dd bs=1 count=$keypresses 2> /dev/null)
stty "$old_tty_setting"
echo "You pressed the \"$keys\" keys."
exit 0

Code brief description :
stty -g Output stty Current settings , Stored in variables old_tty_setting in
stty -icanon -echo The standard input content will not be displayed on the terminal screen
dd bs=1 count=$keypresses 2> /dev/null There's no setup here if, Standard input will be used by default . Match the above stty Set up , Keyboard input is realized ( Standard input ) The content is dd Command to get , Stored in variable keys
stty "$old_tty_setting" Restore the original settings
边栏推荐
- 【LeetCode】two num·两数之和
- Conditional grouping with $exists inside $cond
- 【批处理DOS-CMD命令-汇总和小结】-文件与目录操作命令(md、rd、xcopy、dir、cd、set、move、copy、del、type、sort)
- The principle of Zener diode, what is its function?
- The e-book "action guide for large organizations to further promote zero code application platform" was officially released!
- Redirect to previous page after login? PHP - Redirecting to previous page after login? PHP
- Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
- What is the difference between norflash and nandflash
- 高数基础_函数的奇偶性
- 几款不错的天气插件
猜你喜欢

13 `bs_ duixiang. Tag tag ` get a tag object

Enter an integer with any number of bits, and output the sum of each bit of the number. For example: 1234 – > 10
![[batch dos-cmd command - summary and summary] - CMD window setting and operation commands (CD, title, mode, color, pause, CHCP, exit)](/img/8c/7345b4e8a55dcf11d18ac113df4fc2.png)
[batch dos-cmd command - summary and summary] - CMD window setting and operation commands (CD, title, mode, color, pause, CHCP, exit)

VectorDraw Developer Framework 10.10

Ca-is1200u current detection isolation amplifier has been delivered in batch

威迈斯新能源冲刺科创板:年营收17亿 应收账款账面价值近4亿
![[Batch dos - cmd Command - Summary and Summary] - cmd extension Command, extension Function (CMD / E: on, CMD / E: off)](/img/2b/4495a6cd41a2dd4e7a20ee60b398c9.png)
[Batch dos - cmd Command - Summary and Summary] - cmd extension Command, extension Function (CMD / E: on, CMD / E: off)
![[XXL job] the pond is green and the wind is warm. I remember that Yu Zhen first met](/img/fe/864e9d91be2e0afb163cb8496ae0d2.png)
[XXL job] the pond is green and the wind is warm. I remember that Yu Zhen first met

Path planner based on time potential function in dynamic environment

My debut is finished!
随机推荐
【Qt】快捷键
Path planner based on time potential function in dynamic environment
LabVIEW jump to web page
鸿蒙页面菜单的选择
Introduction to Sichuan Tuwei ca-is3082wx isolated rs-485/rs-422 transceiver
几款不错的天气插件
The perfect presentation of Dao in the metauniverse, and platofarm creates a farm themed metauniverse
Using awk to process input from multiple files
Reading sensor data with GPIO analog SPI interface
How do I get red green blue (RGB) and alpha back from a UIColor object?
图扑软件数字孪生 3D 风电场,智慧风电之海上风电
全局变量&局部变量
TEMPEST HDMI泄漏接收 2
Application scheme | application of Sichuan earth microelectronics ca-is398x in PLC field
[pytest] modify the logo and parameterization in the allure Report
为什么要“除夕”,原来是内存爆了!
This year, I graduated
Ltpowercad II and ltpowerplanner III
Vscode official configuration synchronization scheme
STL教程4-输入输出流和对象序列化