Modify terminal command line settings
The stty command is used to change and print terminal line settings.
stty (options) (parameters)
-a: Print all current settings in a human-readable format.
-g: Print all current settings in a format readable by stty.
Terminal settings: Specify terminal command line setting options.
Disable uppercase output on the command line:
stty iuclc # Enable
stty -iuclc # Restore
Disable lowercase output on the command line:
stty olcuc # Enable
stty -olcuc # Restore
Print terminal rows and columns:
stty size
Change the Ctrl+D (EOF) key:
stty eof "string"
The system defaults to Ctrl+D to indicate EOF; this method allows you to change it.
Toggle echoing:
stty -echo # Disable echo
stty echo # Enable echo
Test method:
stty -echo; read; stty echo; read
Ignore carriage returns:
stty igncr # Enable
stty -igncr # Restore
Timed input:
timeout_read()
{
timeout=$1
old_stty_settings=`stty -g` # Save current settings
stty -icanon min 0 time 100 # Set to 10 seconds (time is in deciseconds)
eval read varname # Read into varname
stty "$old_stty_settings" # Recover settings
}
A simpler method is using the -t option of the read command:
read -t 10 varname