From: http://codingstandards.iteye.com/blog/826924
Description
The stty command is used to display and modify the terminal line settings (Change and print terminal line settings ).
Common Parameters
The stty command can print the terminal line settings without parameters, and the-a parameter can be printed for more details.
The stty size can display the terminal size, that is, the number of rows and the number of columns.
The stty command can also change the terminal line settings in the following format:
Stty setting char
The setting can be as follows:
EOF: End of input and end of file. The default value is Ctrl + D. For example, when you use Cat> file to create a file, press Ctrl + D to end the input.
Erase: Delete the character backward and erase the last input character. The default value is Ctrl + ?. Note that the backspace key is not a delete character by default.
Intr: interrupts the current program. The default value is Ctrl + C.
Kill: Delete the entire command and delete the entire line. The default value is Ctrl + U.
Quit: exit the current program. The default value is Ctrl + \ or Ctrl + |.
Start: Start the screen output. The default value is Ctrl + q.
Stop: Stop the screen output. The default value is Ctrl + S. Sometimes the terminal suddenly freezes, maybe because we accidentally press Ctrl + S, because we habitually press Ctrl + S to save the file.
Susp: terminal stop current program. The default value is Ctrl + Z. In this way, the current process will become a background process.
Werase: Delete the last word. The default value is Ctrl + W.
The stty command also has some other usage, such:
Stty-echo to disable echo. For example, when the password is entered in the script.
Stty echo open echo.
Script snippet for entering the password: stty-echo; read var; stty echo; or read-s var
Example 1: Print terminal line settings
[Root @ Web ~] # Stty
Speed38400 baud; line = 0;
-Brkint-imaxbel
[Root @ Web ~] # Stty-
Speed 38400 baud; rows 41; columns 132; line = 0;
Intr = ^ C; quit = ^ \; erase = ^ ?; Kill = ^ U; EOF = ^ d; EOL = <UNDEF>; eol2 = <UNDEF>; swtch = <UNDEF>; Start = ^ Q; stop = ^ s;
Susp = ^ Z; rprnt = ^ r; werase = ^ W; lnext = ^ V; flush = ^ O; min = 1; time = 0;
-Parenb-parodd cs8-hupcl-cstopb cread-clocal-crtscts-cdtrdsr
-Ignbrk-brkint-ignpar-parmrk-inpck-istrip-inlcr-igncr icrnl ixon-ixoff-iuclc-ixany-imaxbel-iutf8
Opost-olcuc-ocrnl onlcr-onocr-onlret-ofill-ofdel nl0 Cr0 tab0 bs0 vt0 ff0
Isig icanon iexten echo echoe echok-echonl-noflsh-xcase-tostop-echoprt echoctl echoke
[Root @ Web ~] #
Example 2: print the current terminal size (number of rows and number of columns)
[Root @ Web ~] # Stty size
41 132
Example 3: Set the backspace deletion Behavior
By default, when we press backspace, ^ h is displayed on the screen instead of deleting the previous character. For example, this problem occurs when you use commands such as SFTP/FTP/sqlplus/IJ. We can use the stty command to change the backspace behavior to the previous character.
[Root @ Web ~] # SFTP 192.168.6.12
Connecting to 192.168.6.12...
Root@192.168.6.12's password:
SFTP> Get ABC ^ H ^ h
Couldn't stat Remote File: no such file or directory
File "/root" not found.
SFTP> quit
[Root @ Web ~] #
[Root @ Web ~] #Stty erase ^ h
[Root @ Web ~] # SFTP 192.168.6.12
Connecting to 192.168.6.12...
Root@192.168.6.12's password:
SFTP> Get ABC
Couldn't stat Remote File: no such file or directory
File "/root/ABC" not found.
SFTP> quit
[Root @ Web ~] #
Example 4 press Ctrl + q when editing a file in VI to stop the terminal freezing
[Root @ Web ~] # Vi 1.txt
1
2
3
CTRL + S
~
Note: after pressing CTRL + S, the screen output will be disabled, resulting in terminal freezing.
At this time, press Ctrl + Q to end this situation, because it will allow screen output.
CTRL + q
Example 5 use the TTY command in the bash script
In the following script, obtain the terminal file name to determine whether the script is running in interactive mode or in pipeline mode.
Bash code
- #! /Bin/sh
- Lele_input = $ (TTY)
- Echo "lele_input = $ console_input"
- Command_line = "Java-xmx640m-classpath.: lib/hyjc. jar: lib/log4j-1.2.15.jar: lib/commons-logging-1.1.1.jar: lib/proxool-0.9.0RC3.jar: lib/mysql-connector-java-5.1.10-bin.jar: lib/poi-3.5-ZHY-20091107.jar: lib/jdom-1.1.jar hyjc. SQL. dbcli mhrdb. properties mhrdb"
- If ["$ console_input" = "not a tty"]; then
- $ Command_line
- Elif ["$ (whereis rlwrap)" = "rlwrap:"]; then
- Stty erase ^ h
- $ Command_line
- Else
- Rlwrap-F jdb. rlwrap $ command_line
- Fi