Skip to Content
gnux

sttyx

Print or change terminal line settings.

Mirrors GNU stty. Run it as sttyx, or as gnux sttyx.

Synopsis

sttyx [-F DEVICE | --file=DEVICE] [SETTING]...
sttyx [-F DEVICE | --file=DEVICE] [-a|--all]
sttyx [-F DEVICE | --file=DEVICE] [-g|--save]

GNU reference

Description

sttyx works on the terminal on standard input, or the DEVICE -F names. With no SETTING it prints the speed and the settings that differ from 'sane' ones; -a prints them all, and -g prints them in a form sttyx takes back as a setting, to restore them later. A SETTING turns a mode on (echo) or, with a leading -, off (-echo); sets a control character (intr ^C, erase ^?, eof undef); sets min and time for non-canonical reads, the speed (9600, or ispeed and ospeed), the window size (rows, cols) or the line discipline (Linux); prints the size or the speed (size, speed); or applies a combination: sane resets everything to sensible values, raw and cooked switch line editing off and on, cbreak and -icanon read a key at a time, and evenp, oddp, nl, ek, pass8, litout, tabs, lcase, crt and dec are GNU's other shortcuts. Changes wait for pending output to drain unless -drain is given. The modes are those the system has, so the list differs between Linux, macOS and FreeBSD, as with GNU stty built there. After setting, sttyx reads the settings back and fails if the terminal did not take them all. Windows has no termios, so there every SETTING is checked and then fails with 'Operation not supported'.

gnux's terminal view (BR-13): on a terminal, -a is a panel titled with the device: the speed and size, the control characters in an aligned grid, and the control, input, output and local flags each on lines of their own, set flags colored and unset ones dimmed. -g, the plain listing and settings are GNU's. --pretty[=WHEN] and --theme=NAME, options of gnux's own matched only in full, choose the view (GNUX_PRETTY, GNUX_THEME); piped or redirected output is always GNU's.

Permissions

Needs read access to the terminal; changing it needs no more, but a DEVICE given with -F must be one you may open.

Use cases

  • Reading a password in a script without showing it.
  • Restoring a terminal a crashed program left in raw mode (stty sane).
  • Saving the settings before a change and restoring them afterwards.
  • Setting the speed and framing of a serial line.
  • Finding the size of the terminal in a script.

Flags

  -a, --all                      print all current settings in human-readable form
  -F, --file DEVICE              open and use the specified DEVICE instead of stdin
      --help                     display this help and exit
      --pretty WHEN[="always"]   the gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default
  -g, --save                     print all current settings in a stty-readable form
      --theme NAME               color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default
      --version                  output version information and exit

Examples

Read a password without echoing it

sttyx -echo; read -r pass; sttyx echo; echo

Fix a terminal that a program left in a bad state

sttyx sane

Save the settings, change them, and restore them

saved=$(sttyx -g)
sttyx raw -echo
# ...
sttyx "$saved"
sttyx size
Output
24 80

Set a serial line to 115200 baud, 8 data bits, no parity

sttyx -F /dev/ttyUSB0 115200 cs8 -parenb -cstopb

See every setting

sttyx -a

Make Ctrl-H erase, for an old terminal

sttyx erase ^H

Options

Each option has a page of its own, with its usage and examples.

  • -a, --all: Print all current settings in human-readable form.
  • -F, --file: Open and use the specified DEVICE instead of stdin.
  • --pretty: The gnux terminal view WHEN: 'always' (the default when WHEN is omitted), 'auto' (the default: on a terminal only), or 'never'; GNUX_PRETTY sets the default.
  • -g, --save: Print all current settings in a stty``-readable form.
  • --theme: Color the view with the built-in theme NAME (gnux theme picks and saves one); GNUX_THEME sets the default.

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

sttyx --help                # options, first examples, exit status
gnux help sttyx             # this page: the full manual
gnux help sttyx --OPTION    # one option in depth, with its examples

See also

On this page