Unixコマンド/stty

stty

機能

sttyコマンドは、端末環境の各種パラメータを表示、設定します。
引数なしで実行すると、sttyコマンドはデフォルトの端末環境と現在のその端末に
設定されている環境とで、設定が異なるパラメータの内容を表示します。

形式

stty [オプション] [引数]

オプション

-a         全てのパラメータについて情報を表示する

代表的なパラメータ

▼<通信設定>

パラメータ意味
speed 回線速度端末の回線速度を指定した値(2400,4800,9600)などに設定する
cs8文字サイズを8ビットにする
parend(-parend)パリティの生成を検出し有効にする(無効にする)
-parityparendを無効にし、cs8を設定する。

▼<画面設定>

パラメータ意味
rows n端末の行数をn行に指定する
columns n端末の1行の桁数をn桁に設定する

▼<キー割り当て>

パラメータ意味
erase 制御文字指定した機でカーソルの前の1文字消去。デフォルトは^?(「Del」)
intr 制御文字指定したキーで割り込み(プログラムの実行停止)。デフォルトは^C(「Ctrl+C」)
werase 制御文字指定したキーでカーソルの前の1単語消去。デフォルトは^W(「Ctrl+W」)
kill 制御文字指定したキーで1行抹消。デフォルトは^U(「Ctrl+U」)

(*)制御文字には特殊キーとの組み合わせを指定するのが一般的。
コントロールキーとの組み合わせは、コントロールキーを[^]として表示します。
実際に[^]キーを指定するのではありません。

コマンド例

▼キーの割り当てを変更する

$ stty erase ^H                 文字削除を([Ctrl+H])([BS])にする
$ stty                          変更を確認
lflags: echoe echoke echoctl pendin
oflags: -oxtabs
cflags: cs8 -parenb
erase                           eraseが^Hに変更されている
^H

▼画面の表示サイズを変更する

$ stty columns 132 row 48       画面サイズを132x48に設定する

▼パリティ設定を変更する

$ stty prend                    パリティを有効にする
$ stty -a | grep parend
crlags: cread cs8 parend -parodd hupcl -clocal -cstopb -crtscts -dsrflow
$ stty -parend                  パリティを無効にする
crlags: cread cs8 -parend -parodd hupcl -clocal -cstopb -crtscts -dsrflow

▼端末の環境設定すべてを表示する

$ stty -a
speed 9600 baud; 24 rows; 132 columns;
lflags: icanon isig iexten echo echoe -echok echoke -echonl echoctl
        -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo
        -extproc
iflags: -istrip icrnl -inlcr -igncr ixon -ixoff ixany imaxbel -ignbrk
        brkint -inpck -ignpar -parmrk
oflags: opost onlcr -ocrnl -oxtabs -onocr -onlret
cflags: cread cs8 -parenb -parodd hupcl -clocal -cstopb -crtscts -dsrflow
        -dtrflow -mdmbuf
cchars: discard = ^O; dsusp = ^Y; eof = ^D; eol = <undef>;
        eol2 = <undef>; erase = ^H; erase2 = ^H; intr = ^C; kill = ^U;
        lnext = ^V; min = 1; quit = ^\; reprint = ^R; start = ^Q;
        status = ^T; stop = ^S; susp = ^Z; time = 0; werase = ^W;