How to realize the Shortcut key effect under Linux Bash
This article mainly explains "how to achieve shortcut key effect under Linux Bash". Friends who are interested may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how to achieve shortcut key effect under Linux Bash"!
Always wanted to implement through Bash, as in the VI editor, press a key to perform some kind of operation, a chance to find that stty can be achieved.
Please look at the script first:
#! / bin/sh
# We can use this script to automatically detect keystrokes. As for what it is used for, people have different opinions, and wise people have their own wisdom. "Heroes must have the opportunity to show their talents."
# 2009-12-29 13:00:54 update
# wangxiaoyu (AT) live.com From http://wangxiaoyu.blog.51cto.com
_ tty_setting=$ (stty-g)
Stty-icanon
Stty-echo
# We can use c2 arguement to use keyboard shortcut with 2 characters.
_ key_press=$ (head-C1)
Stty $_ tty_setting
# here is the part to judge the input
#
Case $_ key_press in
A) echo-en "We can replace it here with the command string we want to execute 1\ n"
2) echo-en "We can replace it here with the command string we want to execute 2\ n"
3) echo-en "We can replace it here with the command string 3\ n that we want to execute"
4) echo-en "We can replace it here with the command string 4\ n that we want to execute"
5) echo-en "We can replace it here with the command string we want to execute 5\ n"
6) echo-en "We can replace it here with the command string 6\ n that we want to execute"
Exit 1
*) echo-en "here can be replaced with commands related to the help information of the script\ n"
Esac
Note:
Stty is used to display and modify terminal settings, this complex command can be used in scripts to control the behavior of the terminal or the method of displaying output. Combined with special characters and case or other conditions, we can easily search for files like pressing Ctrol + F.
In the script. Stty-g is used to record the parameters of stty, which can be restored in time after the terminal is modified.
Among them, stty-echo is very common and is often used to require users to enter passwords.
Detailed gossip Linux Bash command query historical event operation function
Talking deeply about LINUX Bash Command Line Editing
In-depth discussion of Linux Bash command and file name extension features
At this point, I believe you have a deeper understanding of "how to achieve shortcut key effect under Linux Bash". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!