当前位置:网站首页>shell小技巧(一百三十四)简单的键盘输入记录器
shell小技巧(一百三十四)简单的键盘输入记录器
2022-06-25 06:39:00 【乐大师】
实现效果:
运行脚本,提示输入4个字符。
输入过程中,未达到4个字符之前五显示。
输入第4个字符后,自动显示输入的4个字符。
#!/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

代码简要说明:
stty -g输出stty当前设置,存储在变量old_tty_setting中
stty -icanon -echo 将不显示标准输入内容于终端屏幕
dd bs=1 count=$keypresses 2> /dev/null 这里没有设置if,会默认使用标准输入。配合上面的stty设置,实现了键盘输入(即标准输入)内容被dd命令获得,存储于变量keys
stty "$old_tty_setting" 恢复原来的设置
边栏推荐
- 313. Binary sum
- How comfortable it is to use Taijiquan to talk about distributed theory!
- From perceptron to transformer, a brief history of deep learning
- 【批处理DOS-CMD命令-汇总和小结】-外部命令-cmd下载命令、抓包命令(wget)
- [pytest] modify the logo and parameterization in the allure Report
- Global variables & local variables
- SQL solve select basic statement
- How is the network connected?
- Pratique de gestion hiérarchique basée sur kubesphere
- 5g private network market is in full swing, and it is crucial to solve deployment difficulties in 2022
猜你喜欢

Tempest HDMI leak receive 1
![[batch dos-cmd command - summary and summary] - CMD extended command and function (CMD /e:on, CMD /e:off)](/img/2b/4495a6cd41a2dd4e7a20ee60b398c9.png)
[batch dos-cmd command - summary and summary] - CMD extended command and function (CMD /e:on, CMD /e:off)

We are different
![[pytest] modify the logo and parameterization in the allure Report](/img/c0/93519da008ec137c447bb11aa7b73e.png)
[pytest] modify the logo and parameterization in the allure Report

In depth analysis of Apache bookkeeper series: Part 3 - reading principle

Sqlmap advanced use – cookies

赚够钱回老家吗

Advanced mathematics foundation_ Parity of functions

How is the network connected?

5g private network market is in full swing, and it is crucial to solve deployment difficulties in 2022
随机推荐
Several good weather plug-ins
Large funds support ecological construction, and Plato farm builds a real meta universe with Dao as its governance
Alphassl wildcard certificate for one month
Design a MySQL table for message queue to store message data
lotus v1.16.0-rc3 calibnet
Explain distributed raft with dynamic diagram
Redirect to previous page after login? PHP - Redirecting to previous page after login? PHP
Operate cnblogs metaweblog API
Don't you know the evolution process and principle of such a comprehensive redis cluster model?
Tempest HDMI leak receive 2
MySQL (12) -- Notes on changing tables
[leetcode] two num · sum of two numbers
Sqlmap advanced use – cookies
TEMPEST HDMI泄漏接收 2
Tempest HDMI leak receive 1
One year's time and University experience sharing with CSDN
lotus v1.16.0-rc2 Calibration-net
Genuine photoshop2022 purchase experience sharing
Loopholes in the missed scanning system of Lvmeng and its repair scheme
What is the new business model of Taishan crowdfunding in 2022?