Stty
Encyclopedia
The Unix
Unix
Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&T employees at Bell Labs, including Ken Thompson, Dennis Ritchie, Brian Kernighan, Douglas McIlroy, and Joe Ossanna...

 stty command
Command (computing)
In computing, a command is a directive to a computer program acting as an interpreter of some kind, in order to perform a specific task. Most commonly a command is a directive to some kind of command line interface, such as a shell....

 is used for changing the settings of a Unix computer terminal
Computer terminal
A computer terminal is an electronic or electromechanical hardware device that is used for entering data into, and displaying data from, a computer or a computing system...

. This command is used to change keystrokes, irregular character handling, and more. Stty gives a full set of features that are also available in ncurses
Ncurses
ncurses is a programming library that provides an API which allows the programmer to write text user interfaces in a terminal-independent manner. It is a toolkit for developing "GUI-like" application software that runs under a terminal emulator...

 for programmers but simplifies it by building it in to a simple-to-use Unix command. Now it is rarely used due to reduced use of command lines and UART/RS-232
RS-232
In telecommunications, RS-232 is the traditional name for a series of standards for serial binary single-ended data and control signals connecting between a DTE and a DCE . It is commonly used in computer serial ports...

 serial port
Serial port
In computing, a serial port is a serial communication physical interface through which information transfers in or out one bit at a time...

s.

Example

A lone stty command gives the baud rate, the line-discipline number
Line discipline
A line discipline is a layer in the terminal subsystem in some Unix-like systems. The terminal subsystem consists of three layers: the upper layer to provide the character device interface, the lower hardware driver to communicate with the hardware or pseudo terminal, and the middle line...

 (a non-Posix
POSIX
POSIX , an acronym for "Portable Operating System Interface", is a family of standards specified by the IEEE for maintaining compatibility between operating systems...

 setting) and settings that deviate from the values set by stty sane:


$ stty
speed 38400 baud; line = 0;
$ stty erase ^H # Let the key combination Ctrl+H (in caret notation ^H) erase
$ #+ the last character typed.
$ stty
speed 38400 baud; line = 0;
erase = ^H;


To list current terminal line settings:

$ stty -a
speed 38400 baud; rows 38; columns 92; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = ; eol2 = ;
swtch = ; 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
-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


An example of stty is stty -echo which turns off echoing
Echo (computing)
In computing, echo is a command in DOS, OS/2, Microsoft Windows, Singularity, Unix and Unix-like operating systems that places a string on the computer terminal...

 in the terminal meaning nothing you type will get printed (stty echo to turn the echo back on). An example of that command in a shell script
Shell script
A shell script is a script written for the shell, or command line interpreter, of an operating system. It is often considered a simple domain-specific programming language...

 that stores terminal settings, reads the user's password without echoing it and restores the terminal settings:

  1. !/bin/bash
  2. Reading a password without echoing it while typed


old_term_settings=$(stty -g) # Save all current terminal settings.
stty -echo # Turn off screen echo.
read -p 'Password: ' secret_passwd # Non-bash: `echo -n 'Password: '; read secret_passwd'.

echo
echo Your password is ${secret_passwd}.

stty "$old_term_settings" # Restore all previous settings.

exit 0


To change the row and column size of pseudo terminal
Pseudo terminal
In some operating systems, including Unix, a pseudo terminal is a pseudo-device pair that provides a text terminal interface without an associated device, such as a virtual console, computer terminal or serial port...

pts/13:

stty -F /dev/pts/13 rows 35 columns 59


And to restore the TTY device to normal settings (same as stty cread -ignbrk brkint -inlcr -igncr icrnl -ixoff -iuclc -ixany imaxbel 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):


$ stty sane
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK