📄 345-347.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=345-347//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="343-345.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="347-349.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<P>The <TT>PATH</TT> variable contains a colon-delimited string that points to all the directories containing the programs you use. The order in which these directories are listed determines which directories are searched first. The list order is important on systems that support several different forms of the same command. Your system may also have locally created commands you may want to access. For example, your <TT>PATH</TT> variable may contain the following values:</P>
<!-- CODE SNIP //-->
<PRE>
/usr/ucb:/bin:/usr/bin:/usr/local/bin
</PRE>
<!-- END CODE SNIP //-->
<P>This statement tells your shell to explore the /usr/ucb directory first. If the shell finds the command in the first directory it searches, it stops searching and executes that command. The /bin and /usr/bin directories contain all the standard Linux commands. The /usr/local/bin directory often contains the local commands added by you and other users of your system. This task of adding local commands is usually the responsibility of the system administrator.
</P>
<P>If you are acting as the system administrator, or if you want access to the more system-oriented commands, you will probably want to add /usr/sbin or /usr/local/sbin or both to shorten the effort of typing /usr/sbin/traceroute.</P>
<P>If you intend to create your own commands, you can modify the <TT>PATH</TT> variable to include directories that contain your own commands. How you do this depends on which shell you use. For example, if you use the Bourne or Korn shell, you can add a directory to your <TT>PATH</TT> variable by typing the following at the command prompt:</P>
<!-- CODE SNIP //-->
<PRE>
$ PATH=$PATH:newpath
</PRE>
<!-- END CODE SNIP //-->
<P>When you place a $ in front of the name of a variable, its current value is substituted. In this command, the <TT>$PATH</TT> variable represents whatever the current path is; the colon and the <BIG>newpath</BIG> parameters add to the current path.</P>
<P>The following section describes several other ways of manipulating variables in your environment. For now, it’s sufficient to say that the shell environment contains variables and functions and that these objects can be manipulated by both shells and application programs. Application programs can access and modify the environment, but they generally manipulate variables within the program. Shells, on the other hand, can only manipulate variables in the environment.</P>
<P><FONT SIZE="+1"><B>Using Special Shell Variables</B></FONT></P>
<P>The shell keeps track of a number of special variables. You can see what they are with the <TT>env</TT> command, which lists the variables available to you within your working environment. Following is an abbreviated list of what you might see when you enter <TT>env</TT>:</P>
<!-- CODE SNIP //-->
<PRE>
HOME=/usr/wrev
SHELL=/bin/sh
MAIL=/usr/mail/wrev
LOGNAME=wrev
PATH=/bin:/usr/bin:.
TZ=PST8PDT
PS1=$
TERM=vt100
</PRE>
<!-- END CODE SNIP //-->
<P>Any of these special variables can be used in the same way you use any other shell variable. Table 18.3 defines the special variables.
</P>
<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 18.3</B> Special Environment Variables
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TH WIDTH="28%" ALIGN="LEFT">Variable Name
<TH WIDTH="72%" ALIGN="LEFT">Meaning
<TR>
<TH COLSPAN="2"><HR>
<TR>
<TD><TT>HOME</TT>
<TD>Full path name of your home directory
<TR>
<TD><TT>SHELL</TT>
<TD>Name of your current shell
<TR>
<TD><TT>MAIL</TT>
<TD>Full path name of your mailbox
<TR>
<TD><TT>LOGNAME</TT>
<TD>Your login name
<TR>
<TD><TT>PATH</TT>
<TD>Directories the shell searches for commands
<TR>
<TD><TT>TZ</TT>
<TD>Time zone for the <TT>date</TT> command
<TR>
<TD><TT>SECONDS</TT>
<TD>Number of seconds since invoking shell
<TR>
<TD><TT>PS1</TT>
<TD>System prompt
<TR>
<TD><TT>TERM</TT>
<TD>The type of terminal you’re using
<TR>
<TD COLSPAN="2"><HR>
</TABLE>
<P><FONT SIZE="+1"><B>The HOME Variable</B></FONT></P>
<P>The <SMALL>HOME</SMALL> variable always specifies your home directory. When you log in, you’re in your home directory. Occasionally, you use the <TT>cd</TT> command to move to other directories. To change to the directory /usr/local/games, for example, enter <TT>cd/usr/local/games</TT>. To get back to your home directory, all you have to do is enter <TT>cd</TT>. You can use the <TT>HOME</TT> variable when you’re writing shell scripts that specify files in your home directory. Rather than write a command such as <TT>grep $number /usr/wrev/sales/data.01</TT>, it’s better to enter the command as <TT>grep $number $HOME/sales/data.01</TT> for these reasons:</P>
<DL>
<DD><B>•</B> The command line is easier to read.
<DD><B>•</B> If your home directory is moved, the command still works.
<DD><B>•</B> $HOME always represents the home directory of whoever is using the command. If you enter the command by using <TT>$HOME</TT>, others can use the command as well.
</DL>
<P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="343-345.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="347-349.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 + -