Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use bash Shortcut in Linux

Shulou Source: shulou.com Published: 2022-06-01 04:50:37 09月10日 Update

This article will explain in detail how to use bash shortcuts in Linux. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

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.

This is the end of this article on "how to use bash shortcuts in Linux". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Commands characters strings scripts articles terminals shortcuts more help input good complex practical special benevolent wise opportunities for talent benevolent information content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Docker Microsoft Linux OPPO Reno