⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 343-345.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Understanding Linux Shells</TITLE>

<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
        var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>

 -->




<!--ISBN=0789717468//-->

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=18//-->

<!--PAGES=343-345//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="341-343.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="345-347.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P>The command used to set and display these control-key parameters is <TT>stty</TT>, which stands for <BIG>set teletype</BIG>. In the &#147;old days,&#148; a teletype terminal was the only terminal available; a lot of UNIX terminology is left over from this era. For example, your terminal is defined as a tty device with a name such as tty14. To display all your present settings, enter <TT>stty -a</TT> from the command line. If you use this command, you see something like this:</P>

<!-- CODE //-->

<PRE>

speed 38400 baud; rows 25; columns 80; line = 0;

intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;;

eol2 = &lt;undef&gt;; 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

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

</PRE>

<!-- END CODE //-->

<P>Notice that on this system, the interrupt key (<TT>intr</TT>) is defined as &lt;Ctrl-c&gt; (shown as <TT>^C</TT>), and the kill key is &lt;Ctrl-u&gt;. Although you can set all the settings listed here, as a matter of practicality, users usually only reset the interrupt and kill keys. For example, if you want to change the kill key from <TT>^U</TT> to <TT>^C</TT>, enter the following:</P>

<!-- CODE SNIP //-->

<PRE>

stty kill &#145;^C&#146;

</PRE>

<!-- END CODE SNIP //-->

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>If your terminal is behaving strangely, reset it to a &#147;most reasonable&#148; setting by giving the command <TT>stty sane</TT>.<HR></FONT>

</BLOCKQUOTE>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TIP:&nbsp;&nbsp;</B>If you want a certain setting to take effect every time you log in, place the command in your .profile file (located in your home directory) if you&#146;re running the <TT>bash</TT>, Bourne, or Korn shell. For the C shell, place the command in your .login file.<HR></FONT>

</BLOCKQUOTE>

<P><FONT SIZE="+1"><B>Setting the Shell Environment</B></FONT></P>

<P>Part of the process of logging in&#151;that is, of creating a Linux session&#151;is the creation of your environment. All Linux <BIG>processes</BIG> (as running programs are called) have their own environment separate and distinct from the program itself. It could be said that a program runs from within an environment. The Linux environment, called the <BIG>shell environment</BIG>, consists of a number of variables and their values. These variables and values allow a running program, such as a shell, to determine what the environment looks like.</P>

<P><BIG>Environment</BIG> refers to things such as the shell that you use, your home directory, and what type of terminal you&#146;re using. Many of these variables are defined during the login process and either can&#146;t or shouldn&#146;t be changed. You can add or change as many variables as you like as long as a variable hasn&#146;t been marked &#147;read-only.&#148;</P>

<P>Variables are set in the environment in the form <TT>VARIABLE=value</TT>. The meaning of <TT>VARIABLE</TT> can be set to anything you like. However, many variables have predefined meanings to many standard Linux programs. For example, the <TT>TERM</TT> variable is defined as being the name of your terminal type, as specified in one of the standard Linux terminal databases. Digital Equipment Corporation for years made a popular terminal named the VT-100. The characteristics of this terminal have been copied by many other manufacturers and often emulated in software for personal computers. The name of such a terminal type is vt100; it&#146;s represented in the environment as <TT>TERM=vt100</TT>.</P>

<P>Many other predefined variables exist in your environment. If you use the C shell, you can list these variables with the <TT>printenv</TT> command; with the Bourne or Korn shell, use the <TT>set</TT> command. Table 18.2 lists the most common environment variables and their uses. The Variable column shows what you type at the command line.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>Some environment and system variables can be changed, and some can&#146;t be changed.<HR></FONT>

</BLOCKQUOTE>

<TABLE WIDTH="100%">

<CAPTION ALIGN=LEFT><B>Table 18.2</B> Common Bourne Shell Environment Variables

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="30%" ALIGN="LEFT">Variable

<TH WIDTH="70%" ALIGN="LEFT">Description

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>HOME=/home/login</TT>

<TD><TT>HOME</TT> sets your home directory, which is the location that you start out from. Replace <BIG>login</BIG> with your login ID. For example, if your login ID is jack, <TT>HOME</TT> is defined as /home/jack.

<TR>

<TD VALIGN="TOP"><TT>LOGNAME=login</TT>

<TD><TT>LOGNAME</TT> is automatically set the same as your login ID.

<TR>

<TD VALIGN="TOP"><TT>PATH=path</TT>

<TD>The <TT>path</TT> option represents the list of directories that the shell looks through for commands. For example, you can set the path like this: <TT>PATH=/usr:/bin:/usr/local/bin</TT>.

<TR>

<TD VALIGN="TOP"><TT>PS1=prompt</TT>

<TD><TT>PS1</TT> is the primary shell prompt that defines what your prompt looks like. If you don&#146;t set it to anything specific, your prompt is the dollar sign (<TT>$</TT>). If you prefer, you can set it to something more creative. For example, <TT>PS1=&#147;Enter Command &gt;&#148;</TT> displays <TT>Enter Command &gt;</TT> as your command-line prompt.

<TR>

<TD VALIGN="TOP"><TT>PWD=directory</TT>

<TD><TT>PWD</TT> is automatically set for you. It defines where you are in the file system. For example, if you checked <TT>PWD</TT> (by entering <TT>echo $PWD</TT> at the command line) and Linux displays /usr/bin, you&#146;re in the /usr/bin directory. The <TT>pwd</TT> command also displays the current directory.

<TR>

<TD VALIGN="TOP"><TT>SHELL=shell</TT>

<TD><TT>SHELL</TT> identifies the location of the program that serves as your shell. For example, you can set <TT>SHELL</TT> in your .profile or .login file as <TT>SHELL=/bin/ksh</TT> to make the Korn shell your login shell.

<TR>

<TD VALIGN="TOP"><TT>TERM=termtype</TT>

<TD>Sets the name of your terminal type, as specified by the terminal database. For example, you can set <TT>TERM</TT> in your .profile or .login file as <TT>TERM=vt100</TT>.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>If you want an environment variable defined every time you log in, place the definition in your .profile file (located in your home directory) if you&#146;re running the <TT>bash</TT> or Bourne shell. For the C shell, place the definition in your .login file.<HR></FONT>

</BLOCKQUOTE>

<P>Perhaps the single most important variable in your environment is the <TT>PATH</TT> variable.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B>DOS users should be familiar with the <TT>PATH</TT> variable. It performs the same function under both DOS and Linux.<HR></FONT>

</BLOCKQUOTE>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="341-343.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="345-347.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





</td>
</tr>
</table>

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -