220-224.html

来自「linux-unix130.linux.and.unix.ebooks130 l」· HTML 代码 · 共 165 行

HTML
165
字号
<HTML>

<HEAD>

<TITLE>Linux Unleashed, Third Edition:bash</TITLE>

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

 -->




<!--ISBN=0672313723//-->

<!--TITLE=Linux Unleashed, Third Edition//-->

<!--AUTHOR=Tim Parker//-->

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

<!--IMPRINT=Sams//-->

<!--CHAPTER=11//-->

<!--PAGES=220-224//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="218-220.html">Previous</A></TD>

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

<TD><A HREF="../ch12/225-228.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<H3><A NAME="Heading16"></A><FONT COLOR="#000077">Customizing bash</FONT></H3>

<P>Many ways of customizing <TT>bash</TT> have already been described in this chapter. Until now, the changes that you made affected only the current <TT>bash</TT> session. As soon as you quit, all of the customizations will be lost. You can, however, make the customizations more permanent by storing them in a <TT>bash</TT> initialization file.</P>

<P>You can put any commands that you want to be executed each time <TT>bash</TT> is started into this initialization file. Commands that are typically found in this file are <TT>alias</TT> commands and variable initializations.</P>

<P>The <TT>bash</TT> initialization file is named either <TT>.profile</TT>or <TT>.bash_profile</TT>, depending on the version of Linux you are using. For simplicity&#146;s sake, we&#146;ll assume <TT>.profile</TT> is used, although you should substitute the name your Linux system uses. Each user who uses <TT>bash</TT> has a <TT>.profile</TT> file in his home directory. This file is read by <TT>bash</TT> each time it starts, and all of the commands contained within it are executed.</P>

<P>Many Linux systems use a default <TT>profile</TT> file (note the lack of a period before the filename). This file is located in the <TT>/etc</TT> directory and is read when you start <TT>bash</TT>. If you want to add your own customizations to <TT>bash</TT>, you must copy this file into your home directory (if it is not already there) and call it <TT>.profile</TT>.</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>Note:&nbsp;&nbsp;</B><BR>Some setup programs automatically make a copy of the <TT>.profile</TT> file in your home directory for you when they create your login. However, not all routines do this, so you should check your home directory first. Remember that all files starting with a period are hidden and can only be displayed with the <TT>ls -A</TT> or <TT>ls -a</TT> command.<HR></FONT>

</BLOCKQUOTE>

<H3><A NAME="Heading17"></A><FONT COLOR="#000077">bash Command Summary</FONT></H3>

<P>Some of the most useful commands built into the <TT>bash</TT> shell are summarized in Table 11.2.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 11.2.</B> The <TT>bash</TT> commands we&#146;ve used in this chapter.

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TH WIDTH="30%" ALIGN="LEFT"><TT>bash</TT> command

<TH WIDTH="70%" ALIGN="LEFT">What it&#146;s used for

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD VALIGN="TOP"><TT>alias</TT> 

<TD>Used to set <TT>bash</TT> aliases (command nicknames that can be defined by the user).

<TR>

<TD VALIGN="TOP"><TT>bg</TT>

<TD>Background command. Forces a suspended process to continue to execute in the background.

<TR>

<TD VALIGN="TOP"><TT>cd</TT>

<TD>Change working directory. This command changes the current working directory to the directory specified as an argument.

<TR>

<TD><TT>exit</TT>

<TD>Terminates the shell.

<TR>

<TD VALIGN="TOP"><TT>export</TT>

<TD>Causes the value of a variable to be made visible to all subprocesses that belong to the current shell.

<TR>

<TD VALIGN="TOP"><TT>fc</TT>

<TD>Fix command. Used to edit the commands in the current history list.

<TR>

<TD VALIGN="TOP"><TT>fg</TT>

<TD>Foreground command. Forces a suspended process to continue to execute in the foreground.

<TR>

<TD><TT>help</TT>

<TD>Displays help information for <TT>bash</TT> built-in commands.

<TR>

<TD VALIGN="TOP"><TT>history</TT>

<TD>Brings up a list of the last <I>n</I> commands that were entered at the command prompt, where <I>n</I> is a configurable variable specifying the number of commands to remember.

<TR>

<TD><TT>Kill</TT>

<TD>Used to terminate another process.

<TR>

<TD VALIGN="TOP"><TT>pwd</TT>

<TD>Print working directory. Prints the directory in which the user is currently working.

<TR>

<TD VALIGN="TOP"><TT>unalias</TT>

<TD>Used to remove aliases that have been defined using the <TT>alias</TT> command.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P><TT>bash</TT> has many more commands than are listed here, but these are the most frequently used ones. To see the other commands <TT>bash</TT> offers and for more details of the commands listed, refer to the <TT>bash</TT> man page (type <B>man</B> <B>bash</B>).</P>

<H4 ALIGN="LEFT"><A NAME="Heading18"></A><FONT COLOR="#000077">bash Variables</FONT></H4>

<P>There are a lot of variables used by <TT>bash</TT>. Some of the most useful of these variables, including the variable name and a brief description, are shown in Table 11.3.</P>

<TABLE WIDTH="100%"><CAPTION ALIGN=LEFT><B>Table 11.3.</B> the most commonly used <TT>bash</TT> variables.

<TR>

<TH COLSPAN="2"><HR>

<TR>

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

<TH WIDTH="70%" ALIGN="LEFT">What it&#146;s used for

<TR>

<TH COLSPAN="2"><HR>

<TR>

<TD><TT>EDITOR, FCEDIT</TT>

<TD>The default editor for the <TT>fc bash</TT> command.

<TR>

<TD><TT>HISTFILE</TT>

<TD>The file used to store the command history.

<TR>

<TD><TT>HISTSIZE</TT>

<TD>The size of the <TT>history</TT> list.

<TR>

<TD><TT>HOME</TT>

<TD>The <TT>HOME</TT> directory of the current user.

<TR>

<TD VALIGN="TOP"><TT>OLDPWD</TT>

<TD>The previous working directory (the one that was current before the current directory was entered).

<TR>

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

<TD>The search path that <TT>bash</TT> uses when looking for executable files.

<TR>

<TD><TT>PS1</TT>

<TD>The first-level prompt that is displayed on the command line.

<TR>

<TD VALIGN="TOP"><TT>PS2</TT>

<TD>The second-level prompt that is displayed when a command is expecting more input.

<TR>

<TD><TT>PWD</TT>

<TD>The current working directory.

<TR>

<TD VALIGN="TOP"><TT>SECONDS</TT>

<TD>The number of seconds that have elapsed since the current <TT>bash</TT> session was started.

<TR>

<TD COLSPAN="2"><HR>

</TABLE>

<P><TT>bash</TT> has many more variables than are listed here, but the most commonly used ones are shown. To find out the other variables <TT>bash</TT> offers, call up the man page with the command <TT>man bash</TT>.</P>

<H3><A NAME="Heading19"></A><FONT COLOR="#000077">Summary</FONT></H3>

<P>In this chapter you looked at some of the useful features of the Bourne Again Shell, <TT>bash</TT>. You have seen how command completion, aliasing, and job control can all combine to make you more productive and efficient when working with <TT>bash</TT>.</P>

<P>In the next chapter we&#146;ll look at another popular Linux shell, the Public Domain Korn Shell (<TT>pdksh</TT>). It offers many useful features, too, providing you with a choice of shells. If you want to skip ahead to learn about other subjects, feel free:</P>

<DL>

<DD>Learn about shell programming and how you can use it to make your experience with bash more powerful, in Chapter 14, &#147;Shell Programming.&#148;

<DD>Learn about using editors to create and edit files, in Chapter 16, &#147;Text Editors: <TT>vi</TT> and <TT>emacs</TT>.&#148;

</DL>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="218-220.html">Previous</A></TD>

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

<TD><A HREF="../ch12/225-228.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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