STTY(1) General Commands Manual STTY(1)

sttyset the options for a terminal

stty [-a | -g]

stty operands

The stty utility shall set or report on terminal I/O characteristics for the device that is its standard input. Without options or operands specified, it shall report the settings of certain characteristics, usually those that differ from implementation-defined defaults. Otherwise, it shall modify the terminal state according to the specified operands. Detailed information about the modes listed in the first five groups below are described in POSIX. 1 {8} Section 7. Operands in the Combination Modes group (see COMBINATION MODES ) shall be implemented using operands in the previous groups. Some combinations of operands are mutually exclusive on some terminal types; the results of using such combinations are unspecified. Typical implementations of this utility require a communications line configured to use a POSIX. 1 {8} termios interface. On systems where none of these lines are available, and on lines not currently configured to support the POSIX. 1 {8} termios interface, some of the operands need not affect terminal characteristics.

The stty utility shall conform to the utility argument syntax guidelines described in 2.10.2. The following options shall be supported by the implementation:

Write to standard output all the current settings for the terminal.

Write to standard output all the current settings in an unspecified form that can be used as arguments to another invocation of the stty utility on the same system. The form used shall not contain any characters that would require quoting to avoid word expansion by the shell; see 3.6.

The following operands shall be supported by the implementation to set the terminal characteristics:

parenb (−parenb) Enable (disable) parity generation and detection. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}. parodd (−parodd) Select odd (even) parity. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}. cs5 cs6 cs7 cs8 Select character size, if possible. This shall have the effect of setting , , , and , respectively, in the termios c_cflag field, as defined in POSIX. 1 {8}. number Set terminal baud rate to the number given, if possible. If the baud rate is set to zero, the modem control lines shall no longer be asserted. This shall have the effect of setting the input and output termios baud rate values as defined in POSIX. 1 {8}. ispeed number Set terminal input baud rate to the number given, if possible. If the input baud rate is set to zero, the input baud rate shall be specified by the value of the output baud rate. This shall have the effect of setting the input termios baud rate values as defined in POSIX. 1 {8}. ospeed number Set terminal output baud rate to the number given, if possible. If the output baud rate is set to zero, the modem control lines shall no longer be asserted. This shall have the effect of setting the output termios baud rate values as defined in POSIX. 1 {8}. hupcl (−hupcl) Stop asserting modem control lines (do not stop asserting modem control lines) on last close. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}.

hup (−hup) Same as hupcl (−hupcl). cstopb (−cstopb) Use two (one) stop bits per character. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}. cread (−cread) Enable (disable) the receiver. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}. clocal (−clocal) Assume a line without (with) modem control. This shall have the effect of setting (not setting) in the termios c_cflag field, as defined in POSIX. 1 {8}. It is unspecified whether stty shall report an error if an attempt to set a Control Mode fails.

ignbrk (−ignbrk) Ignore (do not ignore) break on input. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. brkint (−brkint) Signal (do not signal) INTR on break. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. ignpar (−ignpar) Ignore (do not ignore) bytes with parity errors. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. parmrk (−parmrk) Mark (do not mark) parity errors. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. inpck (−inpck) Enable (disable) input parity checking. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. istrip (−istrip) Strip (do not strip) input characters to seven bits. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. inlcr (−inlcr) Map (do not map) NL to CR on input. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. igncr (−igncr) Ignore (do not ignore) CR on input. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. icrnl (−icrnl) Map (do not map) CR to NL on input. This shall have the effect of setting (not setting) in the termios

c_iflag field, as defined in POSIX. 1 {8}. ixon (−ixon) Enable (disable) START / STOP output control. Output from the system is stopped when the system receives STOP and started when the system receives START. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}. ixoff (−ixoff) Request that the system send (not send) STOP characters when the input queue is nearly full and START characters to resume data transmission. This shall have the effect of setting (not setting) in the termios c_iflag field, as defined in POSIX. 1 {8}.

opost (−opost) Post-process output (do not post-process output; ignore all other output modes). This shall have the effect of setting (not setting) in the termios c_oflag field, as defined in POSIX. 1 {8}.

isig (−isig) Enable (disable) the checking of characters against the special control characters INTR, QUIT, and SUSP. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. icanon (−icanon) Enable (disable) canonical input ( ERASE and KILL processing). This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. iexten (−iexten) Enable (disable) any implementation-defined special control characters not currently controlled by icanon, isig, ixon, or ixoff. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. echo (−echo) Echo back (do not echo back) every character typed. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. echoe (−echoe) The ERASE character shall (shall not) visually erase the last character in the current line from the display, if possible. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}.

echok (−echok) Echo (do not echo) NL after KILL character. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. echonl (−echonl) Echo (do not echo) NL, even if echo is disabled. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. noflsh (−noflsh) Disable (enable) flush after INTR, QUIT, SUSP. This shall have the effect of setting (not setting) in the termios c_lflag field, as defined in POSIX. 1 {8}. tostop (−tostop) Send for background output. This shall have the effect of setting (not setting) TOSTOP in the termios c_lflag field, as defined in POSIX. 1 {8}.

: Setting TOSTOP has no effect on systems not supporting the POSIX. 1 {8} job control option.

control-character string Set control-character to string. If control-character is one of the character sequences in the first column of Table 4-9, the corresponding POSIX. 1 {8} control character from the second column shall be recognized. This shall have the effect of setting the corresponding element of the termios c_cc array (see POSIX. 1 {8} 7.1.2).

Table 4-9 − stty Control Character Names

control-character POSIX. 1 {8} Subscript Description

eof character eol character erase ERASE character intr INTR character kill KILL character quit QUIT character susp SUSP character start START character stop STOP character

If string is a single character, the control character shall be set to that character. If string is the twocharacter sequence "ˆ−" or the string "undef", the control character shall be set to _POSIX_VDISABLE, if it is in effect for the device; if _POSIX_VDISABLE is

not in effect for the device, it shall be treated as an error. In the POSIX Locale, if string is a two-character sequence beginning with circumflex (ˆ), and the second character is one of those listed in the ˆc column of Table 4-10, the control character shall be set to the corresponding character value in the Value column of the table.

Table 4-10 − stty Circumflex Control Characters

ˆc Value ˆc Value ˆc Value

a, A < > l, L <FF> w, W < > b, B < > m, M <CR> x, X < > c, C < > n, N <SO> y, Y d, D < > o, O <SI> z, Z e, E < > p, P < > [ < > f, F < > q, Q < > \ <FS> g, G < > r, R < > ] <GS> h, H <BS> s, S < > ˆ <RS> i, I <HT> t, T < > _ <US> j, J <LF> u, U < > ? < > k, K <VT> v, V < >

min number time number Set the value of min or time to number. and are used in noncanonical mode input processing (−icanon).

saved settings Set the current terminal characteristics to the saved settings produced by the −g option. evenp or parity Enable parenb and cs7; disable parodd. oddp Enable parenb, cs7, and parodd. −parity, −evenp, or −oddp Disable parenb, and set cs8. nl (−nl) Enable (disable) icrnl. In addition, −nl unsets inlcr and igncr. ek Reset ERASE and KILL characters back to system defaults. sane Reset all modes to some reasonable, unspecified, values.

Although no input is read from standard input, standard input is used to get the current terminal I/O characteristics and to set new terminal I/O characteristics.

None.

The following environment variables shall affect the execution of stty:

This variable shall determine the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_ ) do not specify a locale. See 2.6.

This variable shall determine the locale to be used to override any values for locale categories specified by the settings of LANG or any environment variables beginning with LC_.

This variable shall determine the locale for the interpretation of sequences of bytes of text data as characters (e.g., single- versus multibyte characters in arguments) and which characters are in the class print.

This variable shall determine the language in which messages should be written.

Default.

If operands are specified, no output shall be produced. If the −g option is specified, stty shall write to standard output the current settings in a form that can be used as arguments to another instance of stty on the same system. If the −a option is specified, all of the information as described in OPERANDS
shall be written to standard output. Unless otherwise specified, this information shall be written as <space>-separated tokens in an unspecified format, on one or more

lines, with an unspecified number of tokens per line. Additional information may be written. If no options or operands are specified, an unspecified subset of the information written for the −a option shall be written. If speed information is written as part of the default output, or if the −a option is specified and if the terminal input speed and output speed are the same, the speed information shall be written as follows: "speed %d baud;", <speed> Otherwise, speeds shall be written as: "ispeed %d baud; ospeed %d baud;", <ispeed>, <ospeed> In locales other than the POSIX Locale, the word baud may be changed to something more appropriate in those locales. If control characters are written as part of the default output, or if the −a option is specified, control characters shall be written as: "%s = %s;", <control-character name>, <value> where value is either the character, or some visual representation of the character if it is nonprintable, or the string <undef> if the character is disabled.

Used only for diagnostic messages.

None.

None.

The stty utility shall exit with one of the following values:

The terminal options were read or set successfully.

An error occurred.

Default.

Since POSIX. 1 {8} doesn’t specify any output modes, they are not specified in this standard either. Implementations are expected to provide stty operands corresponding to all of the output modes they support. In many ways outside the scope of POSIX. 2, stty is primarily used to tailor the user interface of the terminal, such as selecting the preferred ERASE and KILL characters. As an application programming utility, stty can be used within shell scripts to alter the terminal settings for the duration of the script. The −g flag is designed to facilitate the saving and restoring of terminal state from the shell level. For example, a program may: saveterm="$( stty -g)" # save terminal state stty (new settings) # set new state ... # ... stty $saveterm # restore terminal state Since the format is unspecified, the saved value is not portable across systems. Since the −a format is so loosely specified, scripts that save and restore terminal settings should use the −g option.

The original stty manual page was taken directly from System V and reflected the System V terminal driver termio. It has been modified to correspond to the POSIX. 1 {8} terminal driver termios. The termios section states that individual disabling of control characters is an option _POSIX_VDISABLE. If enabled, two conventions currently exist for specifying this: System V uses "ˆ-", and BSD uses undef. Both are accepted by POSIX. 2 stty. The other BSD convention of using the letter u was rejected because it conflicts with the actual letter u, which is an acceptable value for a control character. Early drafts did not specify the mapping of ˆc to control characters because the control characters were not specified in the POSIX Locale character set description file requirements. The control character set is now specified in 2.4.1, so the traditional mapping is specified. Note that although the mapping corresponds to control-character key assignments on many terminals that use / 646 {1} (or ) character encodings, the mapping specified here is to the control characters, not their keyboard encodings. The combination options raw and cooked (−raw) were dropped from the standard because the exact values that should be set are not well understood or commonly

agreed on. In particular, termios has no explicit bit, and the options that should be re-enabled (−raw) are not clear. General programming practice is to save the terminal state, change the settings for the duration of the program, and then reset the state. This is easy to do within a C program, however it is not possible for a single invocation of stty to restore the terminal state (−raw) without knowledge of the prior settings. Using the −g option and two calls to stty, a shell application could do this as described above. However, it is impossible to implement this as a single option. Also, it is not clear that changing word size and parity is appropriate. For example, requiring that cooked set cs7 and parenb would be disastrous for users working with 8−bit international character sets. In general, these options are too ill-defined to be of any use. Since termios supports separate speeds for input and output, two new options were added to specify each distinctly. The ixany input mode was removed from Draft 8 on the basis that it could not be implemented on a POSIX. 1 {8} system without extensions. Some historical implementations use standard input to get and set terminal characteristics; others use standard output. Since input from a login TTY is usually restricted to the owner while output to a TTY is frequently open to the world, using standard input provides fewer chances of accidentally (or mischievously) altering the terminal settings of other users. Using standard input also allows stty −a and stty −g output to be redirected for later use. Therefore, usage of standard input is required by this standard. The tostop option was omitted from early drafts through an oversight. It is the only option that requires job control to be effective, and thus could have gone into the as a modification to stty, but since all other terminal control features are in the base standard, tostop was included as well.

September 1991 posix.fail