Stty of shell scripts

Source: Internet
Author: User
Tags control characters eol posix

From:http://blog.chinaunix.net/uid-2522786-id-223518.html

There are many commands for Unix systems, but there are more ways to use commands skillfully. With the accumulation of experience and observing the practice of learning other users, we can also learn how to solve special problems. Here are some of the experiences of using Stty commands in Unix systems, and hope to share them with you.
1. The Stty (set TTY, Setup TTY) command is used to check and modify the communication parameters of the currently registered terminal. The UNIX system provides an important means of controlling the input and terminal output of the keyboard, which can be set by the Stty command for a specific terminal or communication line.
You can use-A in the Stty command to view the settings of the current registration terminal.
$ stty-a that is, after the terminal window is typed (stty-a) and enter, the following is displayed:
Speed 9600 baud; Line =0;intr= del;quit = ^;erase = ^h;kill =^u; EOF = ^d;start=^q;stop=^s
-parenb-parodd CS8-CSTOPB-HUPCL cread-clocal-loblk
-IGNBRK brkint IGNPAR-PARMRK-INPCK istrip-inlcr-igncr ICRNL-IUCLC
Ixon Ixany-ixoff
Isig icanon-xcase Echo Echoe echok-echonl-noflsh
OPOST-OLCUC ONLCR-OCRNL-ONOCR onlret ofill ofdel tab3
when needed, the various options shown here can be reconfigured. each terminal option has its own name (such as Ixon), most of which are either set or cleared. The option is cleared (forbidden) when the corresponding option in Stty is preceded by a minus sign (-), which is set if there is no minus sign.
When you want to modify the values of each selection, you should write the appropriate options correctly in the Stty command. such as command
$ stty-ixon
Sets the flow control to off, while the command
$ stty Ixon
then set it to on. For example: in the shell statement there is this sentence: stty-icanon min 0 timewith-icanon, set a full read operation to a minimum of n charactersmin N: Use-icanon to set a full read operation to a minimum of n characterstime N: Simultaneous use of-icanon, set read timeout to very N secondsYou can set multiple options at the same time in the Stty command:
$ stty Ixon 1200
This command sets the terminal to 1200 baud and the flow control to on.
When the list of selected items is longer, you should be careful that the changes you make are causing confusion in the session. In a typical case, the terminal does not work at all when it is set incorrectly. The recurring phenomenon is that the column output is displayed or the user's keystrokes cannot be properly accepted by the shell. Sometimes newline may only show or walk one line but not back, that is, the newline character entered by the user cannot be read correctly by the shell. The process of establishing a new registered identity usually establishes the correct stty option, which is seldom required for daily use. However, if the variable term is set incorrectly or the user wants to use a new terminal or communication channel (such as a local area network), the Stty option needs to be modified. If you register on a machine and the terminal is operating normally, but later on for some reason, the best solution is to log off and then register with the system. The system will reset the appropriate options when registering. There is also a less stringent workaround:
$ Stty Sane
The command sane most often appears in the collection of Stty options for most terminals. It does not change the rate of communication channels, but when the terminal is chaotic, it can usually produce beneficial effects. The command sane may cause a full screen application (such as VI) to not work correctly, and after you set the option sane, if you cannot resolve any issues, you should log off immediately before registering. If the terminal still does not work correctly after registering, the user's registration may be unsuccessful. If the terminal is already chaotic, the newline key cannot end the command line, and you can use CTRL-J instead of newline until the user executes Stty sane. At this time, then use CTRL-J to terminate the Stty sane, so that the system back to normal.
Several key options for the Stty command are:
Option Parenb the terminal for parity check,-PARENB is forbidden to verify;
The options CS5, CS6, CS7, and CS8 respectively set the character size to 5, 6, 7, and 8 bits;
Options 300, 600, 1200, 2400, 4800, 9600, and 19200 set the baud rate;
CSTOPB and-CSTOPB respectively set two or a stop bit;
Tabs allows the system to use tabs instead of a space sequence, thus reducing the output, the option-tabs only use spaces, which should be used when the terminal does not handle tabs correctly.
2. The stty can also be used to control keys with special control functions. The system may have used ctrl-d as a file terminator, but you might prefer to use ctrl-c. So you can change it using the Stty command:
$ stty EOF C
Where c can be the other special control characters you like.
You can enter control characters directly, preceded by a backslash and a caret (^). Command
$ stty EOF ^c
Set the ctrl-c to the file terminator. This syntax form can also be used to modify the delete character (usually the backspace backspace) and the break character (usually the DEL key). If you want to change the delete character to backspace, you can use the following command:
$ Stty Erase ^h
You can set a session period so that when you type a backspace, the system responds with a backspace, delete, and backspace sequence. You can see that the characters covered with the BACKSPACE key disappear from the display, which is more consistent with your computer's convention. Using commands
$ stty Echoe
This feature can be set to ON.
Terminal mode and its management is one of the most difficult contents in Unix system, and the user manual of the system has the full list of stty options. Before making an attempt, you should consult the manual and analyze it carefully to avoid causing trouble to your work. Stty-Change and print the terminal line settings
General overview
Stty [-F device] [--file=device] [SETTING] ...
Stty [-F device] [--file=device] [-a|--all]
Stty [-F device] [--file=device] [-g|--save] Description
quot Add any additional description here
Print or change terminal properties.
-A,--all
Print all current settings in a readable format
-G,--save
Print all current settings in a terminal-readable format
-F,--file
Opens the specified device and uses this device as input instead of the standard input
--help
Show Help and Exit
--version
Display version information and exit
Option-Using these options before setting will be considered invalid asterisk * indicates non-POSIX settings. Here are some of the system-defined
Available settings:
Special characters
* Dsusp Char Char indicates that a stop signal is sent to the terminal when the input is full
EOF CHAR
Char indicates the end of a file (end input)
EOL CHAR
Char indicates the end of the current line
* Eol2 Char Char is another character that represents the end of the current line
Erase CHAR
Char means erase last input character
Intr CHAR
Char indicates an interrupt signal is sent
Kill CHAR
Char means erase when moving forward
* Lnext Char Char indicates the next character entered
Quit CHAR
Char indicates an exit signal is emitted
* Rprnt Char char indicates refresh when forward
Start CHAR
Char indicates restart output after stop output
Stop CHAR
Char indicates stop output
Susp CHAR
Char indicates a terminal stop signal is sent
* Swtch Char char means switching to a different shell layer
* Werase Char char means erase the last word already entered
Special settings
N
Set the baud rate of input and output to n
* cols N Notifies the kernel terminal that there are n columns
* Columns n is the same as cols N
Ispeed N
Set input speed to n
* Line n with row constraint rule n
Min N
With-icanon, set a full read operation to a minimum of n characters
Ospeed N
Set output speed to n
* Rows n Notifies the kernel terminal that there are N rows
* Size Prints the number of rows and columns of the terminal based on the kernel
Speed
Print out the speed of the terminal
Time N
At the same time with-icanon, set the read timeout to very n seconds
Control settings
[-]clocal
Turn off the demodulator control signal
[-]cread
Allow incoming input
* [-]crtscts allows rts/cts to shake hands
CsN
Set the character length to N and N to [5..8]
[-]CSTOPB
Use two stop bits per character (one with '-')
[-]hup
When the last process shuts down the terminal, send a hang signal
[-]HUPCL
with [-]hup
[-]parenb
Generates parity bits in the output and requires parity bits in the input
[-]parodd
Set odd check (parity with '-')
Input settings:
[-]brkint
Pause and generate interrupt signal
[-]ICRNL
Interpret a carriage return as a line break
[-]IGNBRK
Ignore interrupt signal
[-]IGNCR
Ignore carriage return characters
[-]ignpar
Ignore characters that have parity errors
* [-]imaxbel generates a beep on a character but does not flush the full input buffer
[-]INLCR
Interpret line breaks as carriage returns
[-]INPCK
Turn on input parity
[-]istrip
Clears the high position of the input character (8th bit)
* [-]IUCLC to convert uppercase characters to lowercase characters
* [-]ixany allows any character to restart the output (rather than just re-output characters to achieve this function)
[-]ixoff
Turn on switch to send start/stop character
[-]ixon
Turn on Xon/xoff flow control
[-]parmrk
Mark parity errors (using the 255-0-character character sequence)
[-]tandem
with [-]ixoff
Output settings:
* BsN fallback delay, N = [0..1]
* CrN return delay, N = [0..3]
* FfN page Change delay, N = [0..1]
* NLN newline delay, N = [0..1]
* [-]OCRNL to interpret carriage return as line break
* [-]ofdel is populated with delete characters instead of empty characters
* [-]ofill using fill characters, without using timing delay
* [-]OLCUC Convert lowercase characters to uppercase
* [-]ONLCR is interpreted as carriage return-line break
* [-]onlret Line to perform a carriage return
* [-]ONOCR not print enter in first column
[-]opost
PostProcess output
* TABN Horizontal tab delay, N = [0..3]
* Tabs with Tab0
*-tabs with TAB3
* VtN Vertical Tab delay ... , N is [0..1]
Local Settings:
[-]crterase
Display erase characters as: backspace-spaces-BACKSPACE
* Crtkill Remove all rows according to ECHOPRT and Echoe settings
*-crtkill removes all rows according to Echoctl and Echok settings
* [-]ctlecho Display the control character ' ^c ' in the head symbol)
[-]echo
Show input characters
* [-]echoctl with [-]ctlecho
[-]echoe
with [-]crterase
[-]echok
Displays a newline after a kill character
* [-]echoke with [-]crtkill
[-]echonl
Line breaks even if no other characters are displayed
* [-]echoprt backward display of erase characters between ' and '/'
[-]icanon
Open Erase, Kill, Werase, and rprnt these special characters
[-]iexten
Open non-POSIX special characters
[-]isig
Open interrupts, exit and suspend these special characters
[-]noflsh
Disable refresh after breaking and exiting these special characters
* [-]prterase with [-]echoprt
* [-]tostop stop trying to write the terminal's background job
* [-]xcase and Icanon are used at the same time, indicating ' exit uppercase ' status
General Settings:
* [-]lcase with [-]lcase
Cbreak
With-icanon
-cbreak
With Icanon
Cooked
Same as Brkint ignpar istrip icrnl ixon opost isig Icanon, EOF and EOL characters are set to default values
-cooked
With raw
Crt
With Echoe Echoctl Echoke
Dec
With Echoe echoctl echoke-ixany intr ^c erase 0177 kill ^u
* [-]DECCTLQ with [-]ixany
Ek
Will erase, kill the word subscript character for their default value
Evenp
With Parenb-parodd CS7
-evenp
With-parenb CS8
* [-]lcase with xcase IUCLC OLCUC
Litout
With Fb-parenb-istrip-opost CS8
-litout
With Parenb Istrip opost CS7
nl
With-ICRNL-ONLCR
-nl
With ICRNL-INLCR-IGNCR Onlcr-ocrnl-onlret
Oddp
With Parenb parodd CS7
-oddp
With-parenb CS8
[-]parity
with [-]EVENP
Pass8
With-parenb-istrip CS8
-pass8
With Parenb Istrip CS7
Raw
With-ignbrk-brkint-ignpar-parmrk-inpck-istrip-inlcr-igncr-icrnl-ixon-ixoff-iuc Lc-ixany-imaxbel-opost-isig-i Canon-xcase min 1 ti me 0
-raw
With cooked
Sane
With cread-ignbrk brkint-inlcr-igncr icrnl-ixoff-iuclc-ixany Imaxbel opost-olcuc-ocrnl Onlcr-onocr-onlret-ofill-o Fdel nl0 cr0 tab0 bs0 vt0 ff 0 isig icanon iexten echo echoe echok-echonl-noflsh-xcase-tostop-echoprt echoctl Echoke, All special characters use default values.
This command handles terminal lines that are connected to standard input. Output baud rate, line constraint rules, and settings that deviate from the sound stty, without parameters. In the settings, CHAR is read verbatim, or encoded like ^c, 0x37, 0177 or 127; Special values ^-or undefined are used to prohibit special characters.

Stty of shell scripts

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.