3
3

More than 5 years have passed since last update.

端末のエコービットを変える

Posted at

端末のエコービットは、下記のようにすると分かります。
echoと表示されているので現在は、設定されています。-echoの場合は、設定されていない状態です。

[hoge@localhost unixandlinux]$ stty --all
speed 38400 baud; rows 46; columns 158; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = M-^?; eol2 = M-^?; swtch = M-^?; 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
[hoge@localhost unixandlinux]$ 

下記のように現在の状態を取得して、ECHOビットをオフにしてセットする。
これで、offになります。逆にonにする場合は、info.c_lflag |= ECHO;にする。

sample.c
#include <termios.h>

int main(int argc, char *argv[])
{
    struct termios info;

    tcgetattr(0, &info);
    info.c_lflag &= ~ECHO;
    tcsetattr(0, TCSANOW, &info);
    return 0;
}

コマンドでもできます。
コマンドでechoビットを落とす場合には、stty -echoを使います。
コマンドでechoビットをあげる場合には、stty echoを使います。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3