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

📄 bash-ch10.html

📁 学习linux的工具书
💻 HTML
📖 第 1 页 / 共 4 页
字号:

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\\</TT> </TD>

		<TD ALIGN="LEFT">Displays a backslash. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\d</TT> </TD>

		<TD ALIGN="LEFT">Displays the current date. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\h</TT> </TD>

		<TD ALIGN="LEFT">Displays the host name of the computer on which the shell is running. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\n</TT> </TD>

		<TD ALIGN="LEFT">Prints a newline character. This will cause the prompt to span more than one line.

					</TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\nnn</TT> </TD>

		<TD ALIGN="LEFT">Displays the character that corresponds to the octal value of the number <TT>nnn</TT>.

					</TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\s</TT> </TD>

		<TD ALIGN="LEFT">The name of the shell that is running. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\t</TT> </TD>

		<TD ALIGN="LEFT">Displays the current time. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\u</TT> </TD>

		<TD ALIGN="LEFT">Displays the user name of the current user. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\W</TT> </TD>

		<TD ALIGN="LEFT">Displays the base name of the current working directory. </TD>

	</TR>

	<TR ALIGN="LEFT" rowspan="1">

		<TD ALIGN="LEFT"><TT>\w</TT> </TD>

		<TD ALIGN="LEFT">Displays the current working directory. </TD>

	</TR>

</TABLE>



</CENTER>

<P><BR>

These special characters can be combined into several useful prompts to provide you

with information about where you are. (They can be combined in very grotesque ways,

too!) Several examples of setting the <TT>PS1</TT> prompt are:<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">PS1=&quot;\t&quot;

</FONT></PRE>

<P>This would cause the prompt to have the following appearance (there would not

be a space after the prompt):<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">02:16:15

</FONT></PRE>

<P>The prompt string<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">PS1=\t

</FONT></PRE>

<P>would cause the prompt to have the following appearance:<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">t

</FONT></PRE>

<P>This shows the importance of including the character sequence in quotation marks.

The prompt string<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">PS1=&quot;\t\\ &quot;

</FONT></PRE>

<P>would cause the prompt to look like this:<FONT COLOR="#0066FF"></FONT>

<PRE><FONT COLOR="#0066FF">02:16:30\

</FONT></PRE>

<P>In this case, there would be a space following the prompt because there was a

space within the quotation marks.

<CENTER>

<H4><A NAME="Heading25<FONT COLOR="#000077">Job Control</FONT></H4>

</CENTER>

<P>Job control refers to the ability to control the execution behavior of a currently

running process. Specifically, you can suspend a running process and cause it to

resume running at a later time. <TT>bash</TT> keeps track of all of the processes

that it started (as a result of user input), and you can suspend a running process

or restart a suspended one at any time during the life of that process.</P>

<P>Pressing Ctrl-Z suspends a running process. The <TT>bg</TT> command restarts a

suspended process in the background, whereas the <TT>fg</TT> command restarts a process

in the foreground.</P>

<P>These commands are most often used when a user wants to run a command in the background

but by accident starts it in the foreground. When a command is started in the foreground,

it locks the shell from any further user interaction until the command completes

execution. This is usually no problem because most commands only take a few seconds

to execute. If the command you are running is going to take a long time, though,

you would typically start the command in the background so that you could continue

to use <TT>bash</TT> to enter other commands in the foreground.</P>

<P>For example, if you started the command <TT>find / -name &quot;test&quot; &gt;

find.out</TT> (which will scan the entire filesystem for files named <TT>test</TT>

and store the results in a file called <TT>find.out</TT>) in the foreground, your

shell may be tied up for many seconds or even minutes, depending on the size of the

filesystem and the number of users on the system. If you had issued this command

and wanted to continue executing in the background so you could use the system again,

you would enter the following:</P>

<PRE><FONT COLOR="#0066FF">control-z

bg

</FONT></PRE>

<P>This would first suspend the <TT>find</TT> command, then restart it in the background.

The <TT>find</TT> command would continue to execute, and you would have <TT>bash</TT>

back again.

<CENTER>

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

</CENTER>

<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 that you made will be lost. You can

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 alias commands and variable initializations.</P>

<P>The <TT>bash</TT> initialization file is named <TT>profile</TT>. 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>The following code shows the default <TT>.profile</TT> file. 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>.



<DL>

	<DT></DT>

</DL>





<DL>

	<DD>

<HR>

<A NAME="Heading27<FONT COLOR="#000077"><B>NOTE:</B> </FONT>Some setup programs

	make a copy of the <TT>.profile</TT> file in your home directory for you automatically

	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>



</DL>



<PRE><FONT COLOR="#0066FF"># commands common to all logins

export OPENWINHOME=/usr/openwin

export MINICOM=&quot;-c on&quot;

export MANPATH=/usr/local/man:/usr/man/preformat:/usr/man:/X11/man:/usr/openwin /man

export HOSTNAME=&quot;`cat /etc/HOSTNAME`&quot;

PATH=&quot;$PATH:/usr/X11/bin:$OPENWINHOME/bin:/usr/games:.&quot;

LESS=-MM

# I had problems using 'eval test' instead of 'TERM=', but you might want to # try it anyway. I think with the right /etc/termcap it would work great.  # eval 'tset -sQ &quot;$TERM&quot;'if [ &quot;$TERM&quot; = &quot;&quot; -o &quot;$TERM&quot; = 
&quot;unknown&quot;]; then 

TERM=linux

#PS1=''hostname':'pwd'# `

if [ &quot;$SHELL&quot; = &quot;/bin/pdksh&quot; -o &quot;$SHELL&quot; = &quot;/bin/ksh&quot; ]; then

 PS1=&quot;! $&quot;

elif [ &quot;$SHELL&quot; = &quot;/bin/zsh&quot; ]; then

 PS1=&quot;%m:%~%# &quot;

elif [ &quot;$SHELL&quot; = &quot;/bin/ash&quot; ]; then

 PS1=&quot;$ &quot;

else

PS1='\h:\w\$ `

fi

PS2='&gt; `

ignoreeof=10

export PATH DISPLAY LESS TERM PS1 PS2 ignoreeof

umask 022

# set up the color-ls environment variables:

if [ &quot;$SHELL&quot; = &quot;/bin/zsh&quot; l; then

  eval 'dircolors -z'

elif [ &quot;$SHELL&quot; = &quot;/bin/ash&quot; l; then

  eval 'dircolors -s'

else

  eval 'dircolors -b'

fi

echo

fortune

echo

export TAPE=&quot;/dev/nftape&quot;

</FONT></PRE>

<CENTER>

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

</CENTER>

<P>Here are some of the most useful commands built into the <TT>bash</TT> shell:

<TT>alias:</TT> Used to set bash aliases (command nicknames that can be defined by

the user).</P>

<P><TT>bg</TT>: Background command. Forces a suspended process to continue to execute

in the background.</P>

<P><TT>cd</TT>: Change working directory. This command changes the current working

directory to the directory specified as an argument.</P>

<P><TT>exit</TT>: Terminates the shell.</P>

<P><TT>export</TT>: Causes the value of a variable to be made visible to all subprocesses

that belong to the current shell.</P>

<P><TT>fc</TT>: Fix command. Used to edit the commands in the current history list.</P>

<P><TT>fg</TT>: Foreground command. Forces a suspended process to continue to execute

in the foreground.</P>

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

<P><TT>history</TT>: Brings up a list of the last n commands that were entered at

the command prompt, where n is a configurable variable specifying the number of commands

to remember.</P>

<P><TT>kill</TT>: Used to terminate another process.</P>

<P><TT>pwd</TT>: Print working directory. Prints the directory in which the user

is currently working.





<BLOCKQUOTE>

	<P><TT>unalias</TT>: Used to remove aliases that have been defined using the <TT>alias</TT>

	command.



</BLOCKQUOTE>



<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 <TT>man</TT>

<TT>bash</TT>).

<CENTER>

<H3><A NAME="Heading29<FONT COLOR="#000077">bash Variables</FONT></H3>

</CENTER>

<P>Here are some of the most useful <TT>bash</TT> variables, including the variable

name and a brief description: <TT>EDITOR, FCEDIT</TT>: The default editor for the

<TT>fc</TT> <TT>bash</TT> command.</P>

<P><TT>HISTFILE</TT>: The file used to store the command history.</P>

<P><TT>HISTSIZE</TT>: The size of the <TT>history</TT> list.</P>

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

<P><TT>OLDPWD</TT>: The previous working directory (the one that was current before

the current directory was entered).</P>

<P><TT>PATH</TT>: The search path that <TT>bash</TT> uses when looking for executable

files.</P>

<P><TT>PS1</TT>: The first-level prompt that is displayed on the command line.</P>

<P><TT>PS2</TT>: The second-level prompt that is displayed when a command is expecting

more input.</P>

<P><TT>PWD</TT>: The current working directory.





<BLOCKQUOTE>

	<P><TT>SECONDS</TT>: The number of seconds that have elapsed since the current <TT>bash</TT>

	session was started.



</BLOCKQUOTE>



<P><TT>bash</TT> has many more variables than are listed here, but the most commonly

used ones are shown. To find out what other variables <TT>bash</TT> offers, call

the man page with the command <TT>man bash</TT>.

<CENTER>

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

</CENTER>

<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 you will 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.





</BODY>



</HTML>

⌨️ 快捷键说明

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