歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> Linux stty命令

Linux stty命令

日期:2017/3/3 12:48:59   编辑:Linux技術

stty時一個用來改變並打印終端行設置的常用命令。

1 ,在命令行下,禁止輸出大寫的方法

stty -icanon 設置一次性讀完操作,如使用getchar()讀操作,不需要按enter

stty icanon 取消上面設置

stty -a 查看 信息

stty -echo 關閉命令的回顯,即鍵入的任何字符均不在屏幕顯示

stty echo

取消上面設置,取消不顯設置

stty raw 終端驅動處於一次一個字符模式

stty cooked 終端驅動處又回到一次一行模式

stty iuclc #開啟

stty -iuclc #恢復

1.Linux中顯示密碼為*:

int main()

{

char c[7];

int i;

system("stty -icanon");

system("stty -echo");

for(i = 0;i < 6 ;i ++)

{

c[i] = getchar();

printf("*");

}

c[i] = '\0';

system("stty echo");

return 0;

}

2,在命令行下禁止輸出小寫

stty olcuc #開啟

stty -olcuc#恢復

3,打印出終端的行數和列數

stty size

4,改變ctrl+D的方法:

stty eof "string"

系統默認是ctrl+D來表示文件的結束,而通過這種方法,可以改變!

5,屏蔽顯示

stty -echo #禁止回顯

stty echo #打開回顯

測試方法:

stty -echo;read;stty echo;read

6,忽略回車符

stty igncr #開啟

stty -igncr#恢復

7.定時輸入

timeout_read()

{

timeout=$1

old_stty_settings=`stty -g`  #save current settings

stty -icanon min 0 time 100  #set 10seconds,not 100seconds

eval read varname  #=read $varname

stty "$old_stty_settings"  #recover settings

}

更簡單的方法就是利用read命令的-t選項

read -t 10 varname

Copyright © Linux教程網 All Rights Reserved