How to Implement shortcut keys in LinuxBash

Source: Internet
Author: User
Article Title: How to Implement shortcut keys in LinuxBash. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

I always wanted to execute some operations by pressing a key like in the VI editor through Bash. It was a chance to find that stty could be implemented.

First read the script:

#! /Bin/sh

# We can use this script to automatically detect keys. As for what it is used for, if you are benevolent, then the wise may see wisdom. "A hero must be useful ".

#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 cut with 2 characters.

_ Key_press = $ (head-c1)

Stty $ _ tty_setting

# The following section describes how to judge the input.

#

Case $ _ key_press in

A) echo-en "here we can replace it with the command string we want to execute 1 \ n"

;;

2) echo-en "here we can replace it with the command string we want to execute 2 \ n"

;;

3) echo-en "here we can replace it with the command string we want to execute 3 \ n"

;;

4) echo-en "here we can replace it with the command string we want to execute 4 \ n"

;;

5) echo-en "here we can replace it with the command string we want to execute 5 \ n"

;;

6) echo-en "here we can replace it with the command string we want to execute 6 \ n"

Exit 1 ;;

*) Echo-en "here we can replace it with the script help information-related command \ n"

Esac

Note:

Stty is used to display and modify terminal settings. This complex command can be used in scripts to control terminal behavior or display output methods. Combined with special characters and case or other conditions, we can easily search files by pressing Ctrol + F.

Script. Stty-g is used to record stty parameters. After the terminal is modified, it is restored in time after use.

Stty-echo is commonly used to require users to enter passwords.

This article is from the "Greek Open Source" blog, please be sure to keep this source http://wangxiaoyu.blog.51cto.com/922065/251847

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.