{"id":236,"date":"2020-08-18T19:23:47","date_gmt":"2020-08-18T20:23:47","guid":{"rendered":"http:\/\/www.linux-tutorial.info\/?page_id=77"},"modified":"2020-08-22T19:26:39","modified_gmt":"2020-08-22T20:26:39","slug":"this-is-the-page-title-toplevel-71","status":"publish","type":"page","link":"http:\/\/www.linux-tutorial.info\/?page_id=236","title":{"rendered":"Terminal Settings"},"content":{"rendered":"\n<title>Terminal Settings<\/title>\n<p>\nWhenever you work with an <glossary>application<\/glossary>, what you see is\ngoverned by a couple of mechanisms. If you have a serial <glossary>terminal<\/glossary>,\n the flow of data is controlled by the serial line characteristics,\nincluding the <glossary>baud<\/glossary>\nrate, the number of data bits, <glossary>parity<\/glossary>,\n and so on. One aspect that is often\nforgotten or even unknown to many users is the <glossary>terminal<\/glossary>\ncharacteristics, which are used to control  the physical appearance on the screen.  However, most\nof the characteristics still apply, even if you are not connected through a <glossary>serial<\/glossary> terminal.\n<p>\nThe reason is that these conventions date back to the time of tele-typewriters.\nYou had a keyboard on one end of the connection connected to a printer that printed\nout every single character you typed. At that time, it was essential that both ends\nknew what characteristics the connection had. Even as technology advanced there was\nstill a need to ensure both sides communicated in the exact same way. Since you\ncould not guarantee that the default settings were the same on both ends, you needed\na way to change the characteristics so that both ends matched.\n<\/p>\n<question id=\"132\" text=\"What command shows your current terminal settings?\" \/>\n<concept id=\"124\" description=\"The 'stty' command can show you your current terminal settings.\" \/>\n<p>\nAs I mentioned <tutorial id=70>elsewhere<\/tutorial>, the <glossary>serial<\/glossary> line\ncharacteristics are initially determined by the gettydefs file. The characteristics are often\nchanged within the users&#8217; startup scripts (<file type=\"\">.profile<\/file>, <file type=\"\">.login<\/file>, etc.).\nIn addition, you can change them\nyourself by using the <command>stty<\/command> command. Rather than jumping to changing them, lets take a look at what\nour current settings are, which we also do with the <command>stty<\/command> command. With no arguments, stty might give  us something like this: <\/p>\n<p>\n<screenoutput>\nspeed 38400 baud; line = 0;\n-brkint ixoff -imaxbel\n-iexten -echoctl\n<\/screenoutput>\n<question id=\"\" type=\"tf\" text=\"All terminal capabilites are Booleans.\" \/>\n<concept id=\"\" description=\"Some terminal capabilites are Booleans and other can take several different values.\" \/>\n<p>\nThis is pretty straightforward. Settings that are Boolean\nvalues (on or off) are listed by themselves if they are on (ixoff) or have a minus sign in front if\nthey are turned off (-brkint). Settings that can take on different values (like the <glossary>baud<\/glossary> rate)\nappear in two formats: one in which the value simply follows the setting name (speed 38400 baud) and\none in which an equal sign is between them (line=0).\n<\/p>\n<question id=\"434\" text=\"What key combination is typically used for the backspace?\" \/>\n<question id=\"435\" text=\"What key combination is typically used to interrupt running programs?\" \/>\n<question id=\"436\" text=\"What key combination is typically used to interrupt running programs?\" \/>\n<question id=\"438\" text=\"In addition to Ctrl-C, what other key is also used to interrupt programs?\" \/>\n<question id=\"460\" text=\"In principle, the interrupt can be assigned to any key or key combination.\" \/>\n<question id=\"\" type=\"tf\" text=\"Some terminal capabilities like baud rate can take any value.\" \/>\n<question id=\"\" type=\"mc\" text=\"What character indicates that a terminal capability can take on any value?\" \/>\n<p>\nIn general, if a setting has discrete values, like the <glossary>baud<\/glossary>\nrate, there is no equal sign. There is only a discrete number of baud rates\nyou could have (i.e., there is no 2678 baud). If the stty setting is for something that could take\non &#8220;any&#8221; value (like the interrupt key), then there is an equal sign. Normally, the\ninterrupt key is something like <keyinput>Ctrl-C <\/keyinput>or the <keyinput>Delete<\/keyinput> key. However, it could be the <keyinput>f<\/keyinput> key or the\n<keyinput>Down-Arrow<\/keyinput> or whatever.\n<\/p>\n<p>\nThis example shows the more &#8220;significant&#8221; <glossary>terminal<\/glossary> (stty)\nsettings. The top line shows the input and output speed of this <glossary>terminal<\/glossary>,\nwhich is 38400. On the second line, we see that sending a break sends an <glossary>interrupt<\/glossary>\n<glossary>signal<\/glossary> (-brkint).\n<\/p>\n<p>\nSetting these values is very straightforward. For Boolean settings (on or off), the syntax is simply\n<\/p>\n<p>\n<commandexample command=\"stty\">stty &lt;setting&gt;<\/commandexample>\n<\/p>\n<p>to turn it on or<\/p>\n<p>\n<kbd>\n<commandexample command=\"stty\">stty -&lt;setting&gt; <\/commandexample>\n<\/kbd>(note the minus sign in front)\n<\/p>\n<p>\nto turn it off.\n<\/p>\n<p>\nFor example, if I wished to turn on input stripping (in which\nthe character is stripped to 7 bits), the command would look like this: <\/p>\n<p>\n<commandexample command=\"stty\">stty istrip<\/commandexample>\n<\/p>\n<p>\nSettings that require a value have the following syntax:\n<\/p>\n<p>\n<commandexample command=\"stty\">stty &lt;setting&gt;  &lt;value&gt; <\/commandexample>\n<\/p>\n<p>So, to set the speed (baud rate) to 19200, the syntax would look like this:\n<\/p>\n<question id=\"\" type=\"mc\" text=\"What command would you use to set the terminal speed to 19200 baud?\" \/>\n<p>\n<commandexample command=\"stty\">stty speed 19200<\/commandexample>\n<\/p>\n<question id=\"\" type=\"mc\" text=\"What command would you use to set the terminal interrupt character to Ctrl-C?\" \/>\n<p>\nTo set the <glossary>interrupt<\/glossary> character to Ctrl-C, we would enter<\/p>\n<p>\n<commandexample command=\"stty\">stty intr ^C<\/commandexample>\n<\/p>\n<question id=\"\" type=\"tf\" text=\"On most terminals you need to set the 'erase' key separately from the backspace key.\" \/>\n<concept id=\"\" description=\"The backspace key is used for the 'erase' terminal capability.\" \/>\n<p>\nNote that ^C is not two separate characters. Instead, when you type it, hold down the\n<keyinput>Ctrl<\/keyinput> key and press &#8220;c.&#8221; In most documentation you will see that the letter appears as capital although you actually press the\nlowercase letter.  Sometimes you want to assign the particular characteristic to just a single key. For example, it is often\nthe case that you want to use the backspace key to send an &#8220;erase&#8221; character. What the erase character does is tell the system\nto erase the last character, which is exactly what the backspace is supposed to do.  Just like the case where you press the\ncontrol key and the character, <command>stty<\/command> settings  for single keys are done the same way. For example, you would type &#8220;stty erase &#8221; and the\npress the backspace key (followed by the enter key, or course). What you would see might look like this:<\/p>\n<question id=\"\" type=\"mc\" text=\"What command would you use to set the 'erase' key.\" \/>\n<p>\n<commandexample command=\"stty\">stty erase ^?<\/commandexample>\n<p>\nThe ^? is typically what the backspace key will send (at least that is the visual representation of what the backspace sends). You\ncan get the same result by press <keyinput>CTRL-?<\/keyinput>.\n<p>\nIf the default output does not show the particular characteristic you are looking for, you can use the\n<keyinput>-a<\/keyinput> option to show all the characteristics. You might end up with output like this:\n<p>\n<screenoutput>\nspeed 38400 baud; rows 25; columns 80; line = 0;\nintr = ^C; quit = ^\\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;;\neol2 = &lt;undef&gt;; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W;\nlnext = ^V; flush = ^O; min = 1; time = 0;\n-parenb -parodd cs8 hupcl -cstopb cread -clocal -crtscts\n-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon ixoff\n-iuclc -ixany -imaxbel opost -olcuc -ocrnl onlcr -onocr -onlret -ofill\n-ofdel nl0 cr0 tab0 bs0 vt0 ff0\nisig icanon -iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt\n-echoctl echoke\n<\/screenoutput>\n<p>\nHere were see a number of well-known characteristics, such as the <glossary>baud<\/glossary> rate,\nthe numbers of rows and columns, interrupt character, end of file character and so on. Some of\nwhich we talked about in the section on\n<tutorial id=54>working with the system.<\/tutorial> For details on what the rest of these mean,\nplease see the <command>stty<\/command>(1L) <glossary>man-page<\/glossary>.\n<\/p>\n<question id=\"137\" text=\"You would change the your 'delete' key using the stty command.\" \/>\n<concept id=\"126\" description=\"You change special keys like your 'delete' key using the stty command.\" \/>\n<p>\nIn principle, you can set any key to any one of the terminal characteristics. For example,\nI could set the interrupt key to be the letter g:\n<p>\n<commandexample command=\"stty\">stty intr g<\/commandexample>\n<p>\nAlthough this not does make too much sense, it is possible. What does make more sense\nis to set the characteristic to something fitting for your keyboard. For example, you might\nbe using telnet to move between system. The key sequence that your backspace\nsends may not be <keyinput>^?<\/keyinput>  (often it is <keyinput>^H<\/keyinput>) and you want to set it accordingly (or the ase is reversed, as we discussed above.)\n<p>\nTo save, change, and then restore the original values of your <command>stty<\/command>\nsettings, use the &#8211;<keyinput>g<\/keyinput> option. This option outputs the stty settings as a strings of <glossary>hexadecimal<\/glossary> values. For example, I might get something like this: <\/p>\n<p>\n<commandexample command=\"stty\">stty -g<\/commandexample>\n<p>\n<screenoutput>\n500:5:d050d:3b:7f:1c:8:15:4:0:0:0:0:0:1a:11:13:0:0:0:0:0:0:0:0:0\n<\/screenoutput>\n<p>\nWe can run the <command>stty<\/command>\ncommand to get these values and make the changes, then run stty again and use these values as the\nargument. We don&#8217;t have to type in everything manually; we simply take advantage of the fact that\nvariables are expanded by the <glossary>shell<\/glossary>\nbefore being passed to the command. You could use this to add an\nadditional password to your system:<\/p>\n<p>\n<screenoutput>\necho &#8220;Enter your password: \\c&#8221;\noldstty=`stty -g`\nstty -echo intr ^-\nread password\nstty $oldstty\n<\/screenoutput>\n<p>\nAssign the output of the stty command to the <glossary>variable<\/glossary>\nold, then change the stty settings so\nthat the characters you input are not echoed to the screen and the <glossary>interrupt<\/glossary>\nkey is disabled (this\nis done with <commandexample>stty -echo intr ^-<\/commandexample>). Then read a line\nfrom the keyboard and reset the stty settings to their old value.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Terminal Settings Whenever you work with an application, what you see is governed by a couple of mechanisms. If you have a serial terminal, the flow of data is controlled by the serial line characteristics, including the baud rate, the &hellip; <a href=\"http:\/\/www.linux-tutorial.info\/?page_id=236\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-236","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/236","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":1,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/236\/revisions"}],"predecessor-version":[{"id":729,"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=\/wp\/v2\/pages\/236\/revisions\/729"}],"wp:attachment":[{"href":"http:\/\/www.linux-tutorial.info\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}