📄 ch05_05.htm
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 5] 5.5 Querying Your Terminal Type: qterm </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly & Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly & Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:33:03Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch05_01.htm"TITLE="5. Setting Up Your Terminal"><LINKREL="prev"HREF="ch05_04.htm"TITLE="5.4 Setting the TERMCAP Variable with tset "><LINKREL="next"HREF="ch05_06.htm"TITLE="5.6 Checklist: Terminal Hangs When I Log In "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_04.htm"TITLE="5.4 Setting the TERMCAP Variable with tset "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.4 Setting the TERMCAP Variable with tset "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 5<BR>Setting Up Your Terminal</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_06.htm"TITLE="5.6 Checklist: Terminal Hangs When I Log In "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.6 Checklist: Terminal Hangs When I Log In "BORDER="0"></A></TD></TR></TABLE> <HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-9013">5.5 Querying Your Terminal Type: qterm </A></H2><PCLASS="para"><SPANCLASS="link"><EMCLASS="emphasis">tset</EM> (<ACLASS="linkend"HREF="ch05_03.htm"TITLE="Setting the Terminal Type When You Log In ">5.3</A>)</SPAN><ACLASS="indexterm"NAME="AUTOID-5062"></A>is a powerful tool to use if you often log in at different terminals.You can use <EMCLASS="emphasis">tset</EM> to prompt you with a default terminal type,giving you the opportunity to specify a new terminaltype when you log in:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">TERM = (vt100)</PRE></BLOCKQUOTE></P><PCLASS="para">A problem with <EMCLASS="emphasis">tset</EM>, however, is that it requires you to know your terminal type.You might log in at a new terminal and have noidea what to set the terminal type to.Or your terminal might beconfigured to emulate another terminal type, without your knowledge.New users in particular tend to be confused by the <EMCLASS="emphasis">tset</EM> prompt.</P><TABLECLASS="para.programreference"BORDER="1"><TR><THVALIGN="TOP"><ACLASS="programreference"HREF="examples/index.htm"TITLE="qterm">qterm</A><BR></TH><TDVALIGN="TOP"><ACLASS="indexterm"NAME="AUTOID-5071"></A>As an alternative, try Michael Cooper's <EMCLASS="emphasis">qterm</EM> program on our Power Toolsdisc.<EMCLASS="emphasis">qterm</EM> sends the terminal a test string and determines what sort of terminalyou're using based on how the terminal responds.Using <EMCLASS="emphasis">qterm</EM>, you can make sure you always use the correctterminal type by placing the following line in your <EMCLASS="emphasis">.login</EM>:</TD></TR></TABLE><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch09_16.htm"TITLE="9.16 Command Substitution ">`...`</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">setenv TERM `qterm`</PRE></TD></TR></TABLE></P><PCLASS="para">or in <EMCLASS="emphasis">.profile</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">TERM=`qterm`;export TERM</PRE></BLOCKQUOTE></P><PCLASS="para">The advantage of <EMCLASS="emphasis">qterm</EM> is that it sets the terminal typewithout your intervention.You don't need to know what yourterminal type is, it just gets set automatically.</P><PCLASS="para"><EMCLASS="emphasis">qterm</EM> works by sending the terminal a query string andreturning the terminal type depending on the terminal's response.<EMCLASS="emphasis">qterm</EM> is configured using a listing of responses and theterminals they correspond to.By default, <EMCLASS="emphasis">qterm</EM> looks for the listings in a systemwide location, such as <EMCLASS="emphasis">/usr/usc/lib/qtermtab</EM> or <EMCLASS="emphasis">/usr/local/lib/qtermtab</EM>.In addition, you can call <EMCLASS="emphasis">qterm</EM> with the <EMCLASS="emphasis">+usrtab</EM>option, so that it will look for a file called <EMCLASS="emphasis">.qtermtab</EM>in your home directory. </P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5097"></A>The string used to query the terminal is usually ESC Z.The sample <EMCLASS="emphasis">qtermtab</EM> file distributed with <EMCLASS="emphasis">qterm</EM> defines the responses several different terminals give for that string:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">## QtermTab - Query terminal table for qterm.##SendStr ReceiveStr TermName FullTermName#^[Z ^[[?1;0c vt100 Base vt100^[Z ^[[?1;1c vt100 vt100 with STP^[Z ^[[?1;2c vt100 ANSI/VT100 Clone ...^[Z ^[/K h29 Zenith z29 in zenith mode^[Z ^[/Z vt52 Generic vt52^[Z ^[[0n vt100 AT&T UNIX PC 7300</PRE></BLOCKQUOTE></P><PCLASS="para">If your terminal isn't listed here, you can just add it.To findout your terminal's response to the query string, justecho ESC Zto your terminal and see what the response is.For example, I logged in from my Macintosh terminal emulator at home and found that<EMCLASS="emphasis">qterm</EM> didn't recognize my terminal type:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>qterm</B></CODE>Terminal NOT recognized - defaults to "vt100".vt100</PRE></BLOCKQUOTE></P><PCLASS="para"><EMCLASS="emphasis">qterm</EM> defaults to the right terminal description, but I'd stillrather define my own entry.I find out my terminal's response to theESC Z string:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch08_06.htm"TITLE="8.6 Output Command-Line Arguments ">echo</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">% <CODECLASS="userinput"><B>echo "^[Z"</B></CODE>^[[E;Y|</PRE></TD></TR></TABLE></P><PCLASS="para">(Note that ESC prints as <CODECLASS="literal">^[</CODE>.)Then I add the entry to my<EMCLASS="emphasis">qterm</EM> description file:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">^[Z ^[[E;Y| vt100 Macintosh terminal emulator</PRE></BLOCKQUOTE></P><PCLASS="para">Now when I run <EMCLASS="emphasis">qterm</EM>, the terminal is recognized:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>qterm</B></CODE>Terminal recognized as vt100 (Macintosh terminal emulator)vt100</PRE></BLOCKQUOTE></P><PCLASS="para">The string <CODECLASS="literal">Terminal</CODE> <CODECLASS="literal">recognized</CODE> <CODECLASS="literal">as</CODE> <CODECLASS="literal">...</CODE>is sent to<SPANCLASS="link">standard error (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>;only the terminal type itself is sent to<SPANCLASS="link">standard output (<ACLASS="linkend"HREF="ch13_01.htm#UPT-ART-1023"TITLE="Using Standard Input and Output">13.1</A>)</SPAN>.So if youuse the following command line:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>setenv TERM `qterm`</B></CODE>Terminal recognized as vt100 (Macintosh terminal emulator)</PRE></BLOCKQUOTE></P><PCLASS="para">the TERM variable is set correctly:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>echo $TERM</B></CODE>vt100</PRE></BLOCKQUOTE></P><PCLASS="para">Now for the caveat: <EMCLASS="emphasis">qterm</EM>'s results are only as accurate as the <EMCLASS="emphasis">qtermtab</EM> file. Not all terminals respond to the ESC Z string, and you may not beable to find a string that it does respond uniquely to.And someterminals do uncanny imitations of others.For example, I'm currently using an<SPANCLASS="link"><EMCLASS="emphasis">xterm</EM> (<ACLASS="linkend"HREF="ch01_31.htm"TITLE="The X Window System ">1.31</A>)</SPAN>window, but <EMCLASS="emphasis">qterm</EM>thinks I'm using a <EMCLASS="emphasis">vt100</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">% <CODECLASS="userinput"><B>echo $TERM</B></CODE>xterm% <CODECLASS="userinput"><B>qterm</B></CODE>Terminal recognized as vt100 (ANSI/VT100 Clone)vt100</PRE></BLOCKQUOTE></P><PCLASS="para"><ACLASS="indexterm"NAME="AUTOID-5150"></A>As a hack, you can just edit your <EMCLASS="emphasis">.qtermtab</EM> file. For example, I could edit my <EMCLASS="emphasis">.qtermtab</EM> so the<CODECLASS="literal">^[[?1;2c</CODE> response is mapped to <EMCLASS="emphasis">xterm</EM>:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">#^[Z ^[[?1;2c vt100 ANSI/VT100 Clone^[Z ^[[?1;2c xterm xterm window</PRE></BLOCKQUOTE></P><PCLASS="para">And then call <EMCLASS="emphasis">qterm</EM> with the <EMCLASS="emphasis">+usrtab</EM> command-line option:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">setenv TERM `qterm +usrtab`</PRE></BLOCKQUOTE></P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">LM</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_04.htm"TITLE="5.4 Setting the TERMCAP Variable with tset "><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 5.4 Setting the TERMCAP Variable with tset "BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch05_06.htm"TITLE="5.6 Checklist: Terminal Hangs When I Log In "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 5.6 Checklist: Terminal Hangs When I Log In "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">5.4 Setting the TERMCAP Variable with tset </TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">5.6 Checklist: Terminal Hangs When I Log In </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed & awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -