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