+ -

Certification Objective 1.05:Shells

时间:2007-04-01

来源:austin22

在手机上看
手机扫描阅读
Certification Objective 1.05:Shells
认证目的 1.05:Shells

A shell is a user interface.
一个shell是一个使用者介面。

 The Linux command shell is the prompt that allows you to interact with your computer with various system commands.
 Linux 指令shell是让你用各种不同的系统指令与你的计算机互动的提示。

 With the right file permissions, you can set up commands in scripts to run when you want, even in the middle of the night.
 藉由正确的文件许可,当甚至在夜晚中,你想要的时候,你能建立在脚本中的指令运行。

 Linux shells can process commands in various sequences, depending on how you manage the input and output of each command.
 Linux shell能处理各种不同的顺序的指令,仰赖你们如何处理输入和每个指令的输出。

 The way commands are interpreted is in part determined by variables and parameters associated with each shell.
 方法指令被解释部份地被与每个shell有关的变数和叁数决定。

 Some of these variables make up the environment that is carried over even if you change from one shell to another.
 即使你从一个shell变成另外的,一些变数组成结束被传达的环境。

The default shell in Linux is bash, also known as the Bourne Again Shell.
在 Linux 的内定的shell是bash, 也当做小河再知道shell。

 A number of other shells are available that are popular with many users.
 一些其他的shell是可得的,那对许多使用者感到常用。

 As long as you have installed the appropriate RPMs, users can start any of these shells.
 只要你们已经安装适当的 RPMs ,使用者能启动任何的这些shell。

 As desired, you can change the default shell for individual users in the /etc/passwd file.
 当做需要,你能在那 /etc/passwd 文件中将内定的shell换成个别的使用者。

Basic Shell Programming
基本的shell程序设计

'Real' Linux administrators program their own scripts.
'真正的' Linux 系统管理师规划他们自己的脚本。

 They create scripts because they don't want to sit at their computers all of the time.
 因为他们不想要坐在他们的计算机所有的时间前,所以他们产生脚本。

 Scripts can allow Linux to automatically back up directories when nobody is in the office.
 执行绪能让 Linux 到自动地向后地在目录上面当没有人在办公室中的时候。

 Scripts can help Linux process databases when few people are using the system.
 当少数人正在使用系统的时候,执行绪能帮助 Linux 处理数据库。

If you're not a programmer, don't worry-this is not as difficult as it sounds.
如果你不是一个程序设计者, 不烦恼-这不像它那么困难听。

 For example, utilities related to the crontab command automate the creation of a number of different scripts.
 举例来说,对 crontab 指令的讲的公用程式自动化一些不同的脚本的创造。

 The cron system is discussed in more detail in Chapter 5.
 cron 系统在第 5 章更详细地被讨论.

If you're at all familiar with shell commands and programming expressions, you can find some examples of Red Hat Enterprise Linux shell programs in the /etc/cron.daily directory.
如果你是全然熟悉的有着shell指令和程序规划展示语句,你能找红帽企业 Linux shell的一些例子在那 /etc/ cron.daily 目录中规划。

Script Execution and Permissions
执行绪运行和许可

Any Linux file can be set up as an executable file.
任何的 Linux 文件能当做一个可运行的文件被建立。

 Then if the file includes a series of commands that can be interpreted by the shell, the commands in that file are executed.
 然后如果文件包括能被shell解释的一系列的指令,在那一个文件的指令被运行。

 If you want Linux to run a script that you've created, you need to assign executable permissions.
 如果你想要 Linux 运行你已经建立的一个脚本,你需要分配可运行的许可。

 For additional information on executable files, read the information under the 'Basic Security' objective later in this chapter.
 对于关于可运行的文件另外的资讯,读在这一个章节中比较迟的在 '基本的安全[性]' 目的下面的信息。

Variables and Parameters
变数和叁数

Variables can change.
变数能改变。

 Parameters are set.
 叁数被设定。

 The bash shell includes a number of standard environment variables.
 bash shell包括一些标准的环境变数。

 Their default values are shown in the output to the env command.
 他们的内定数值在对 env 指令的输出被显示。

 One critical variable is the value of PATH, which you can check at the command line with the echo $PATH command.
 一个临界变数是路径的数值, 你以回声 $路径指令能在指令行检查。

 The directories listed in PATH are automatically searched when you try to run a command.
 当你试着运行一个指令的时候,在路径被列出的目录自动地被搜寻。

 For example, if you want to run the fdisk command from the /sbin directory, you could do it with the following command:
 举例来说,如果你想要运行来自那 /sbin 目录的 fdisk 指令,你以下列的指令办得到:

$ /sbin/fdisk

However, if the /sbin directory were in your PATH, you don't need the leading /sbin to call out the command; the following would work:
然而, 如果那 /sbin 目录在你的路径中,你不需要领先 /sbin 大叫指令;下列各项会工作:

$ fdisk

You can easily change the PATH variable.
你能容易地改变路径变数。

 For example, if you want to add the /sbin directory to your PATH, just run the following commands:
 举例来说,如果你想要把那 / sbin 目录加入你的路径, 仅仅运行下列的指令:

# PATH=$PATH:/sbin
# export PATH

The /sbin directory is in the default PATH for the root user.
那 /sbin 目录在根使用者的内定的路径中。

 The most common parameters are the settings associated with Linux configuration files, which are mostly located in the /etc directory.
 最通常的叁数是与 Linux 配置文件,大概位于那 /etc目录有关的设定。

 For example, the /etc/resolv.conf file uses the nameserver parameter to represent the DNS servers for your network.
 举例来说, 那 /etc/ resolv.conf 文件使用 nameserver 叁数为你的网络表现 DNS 服务器。

 This is normally set to the IP address for that DNS server.
 这通常被设定成那一个 DNS 服务器的 IP 位址。

Exercise 1-3:Checking the PATH
练习 1-3:检查路径

In this exercise, you'll examine the path for a regular and the root user.
在这练习,你将会调查一个老客户和根使用者的路径。

Log into the Linux command line interface as a regular user.
进入作为一个一般的使用者的 Linux 指令行介面之内纪录。

 If you're in the GUI, you can get to a command line login with the CTRL-ALT-F2 command.
 如果你在图形用户接口中,你能用 CTRL-Alt-F2 的指令到达一个指令行登录。

 From the command prompt, run the following command and note the result:
 从指令提示,运行下列的指令而且注意结果:

$ echo $PATH

From the regular user command line interface, log in as the superuser.
从一般的使用者指令行介面,登录当做超级使用者。

 You'll need the root user's password.
 你将会需要根使用者的口令[字] 。

$ su
Password:
#

Run the following command again and note the result.
再运行下列的指令而且注意结果。

 Compare it to the result as a regular user.
 比较它和作为一个一般的使用者的结果。

 Is there a difference?
 有一个差吗?

 By default there is no difference on regular Red Hat Linux.
 预先设定地,没有差在一般的红帽 Linux 上。

 There is a slight difference when you repeat this process on Red Hat Enterprise Linux.
 当你在红帽企业 Linux 上重复这一程序的时候 , 有一个微小的差。

# echo $PATH

Log out of Linux.
Linux 登出。

 If you followed steps 1, 2, and 3, you'll need to type the exit command twice to log out.
 如果你遵从了第 1,2 步, 和 3, 你将会需要键入出囗指令两次登出。

Now log into Linux as the root user.
现在进入作为根使用者的 Linux 之内纪录。

 At the command prompt, run the following command again and note the result:
 在指令提示,再运行下列的指令而且注意结果:

# echo $PATH

Observe the difference.
观察不同之处。

 You'll see more directories in the PATH for the root user.
 你将会在根使用者的路径中见到较多的目录。

 Now you can see why many Linux gurus who are doing heavy-duty administrative work log in as the root user.
 现在你能见到为什么正在做重任管理的工作纪录的许多 Linux 印度教的导师在当做根使用者。

 And that is why I also recommend that you log in as the root user during the RHCE or RHCT exams.
 而且那是我为什么也推荐你在 RHCE 或 RHCT 考试期间登录如根使用者。

Inherited Environment
继承了环境

It's easy to move from shell to shell.
从shell移到shell很容易。

 While the default Linux shell is bash, many experienced Unix users prefer the Korn shell.
 内定的 Linux shell是bash,不过许多富有经验的 Unix 使用者偏爱 Korn shell。

 Once set, with the set command, environment variables stay the same from shell to shell.
 一次组,藉由固定的指令,环境变数停留从shell到shell的一样的。

 In contrast, shell variables such as umask may change when you move from shell to shell, or even from user to user.
 在对比,当你从shell移到shell的时候,shell变数,像是 umask 可能改变, 或甚至从使用者到使用者。

 For example, umask is typically different for regular users and the root user.
 举例来说, umask 对一般的使用者和根使用者是典型地不同的。

Piping, Input/Output, Error, and Redirection
管道传送、输入/输出、错误和重定向

Linux uses three basic data streams.
Linux 使用三个基本的数据流。

 Data goes in, data comes out, and errors are sent in a different direction.
 数据进入,数据出来,而且错误被送出一个不同的方向。

 These streams are known as standard input (stdin), standard output (stdout), and standard error (stderr).
 这些水流即是标准输入 (stdin), 标准输出 (stdout), 和标准错误 (stderr).

 Normally, input comes from the keyboard and goes out to the screen, while errors are sent to a buffer.
 通常,输入来自键盘而且出去到荧屏而错误被送到一个缓冲区。

 Error messages are also sent to the display (as text stream 2).
 错误信息也被传达到显示装置。 (当做文本水流 2)

 In the following example, filename is stdin to the cat command:
 在下列的例子中,档名是对cat指令的 stdin:

# cat filename

When you run cat filename, the contents of that file are sent to the screen as standard output.
当你运行cat档名的时候,那一个文件的内容当做标准的输出被送到荧屏。

You can redirect each of these streams to or from a file.
你能重新传入每一条这些水流到或从一个文件。

 For example, if you have a program named database and a datafile with a lot of data, the contents of that datafile can be sent to the database program with a left redirection arrow (<).
 举例来说,如果你有一个以许多数据, datafile 能与一支左边的重定向箭一起送到数据库程序的内容叫做数据库和 datafile 的程序。 (<)

 As shown here, datafile is taken as standard input:
 当做在这里显示, datafile 当做标准输入被拿:

# database < datafile

Standard input can come from the left side of a command as well.
标准的输入也能来自指令的左边。

 For example, if you need to scroll through the boot messages, you can combine the dmesg and less commands with a pipe:
 举例来说,如果你需要检视启动信息,你能结合 dmesg 和比较少的指令和一个管道:

# dmesg | less

The output from dmesg is redirected as standard input to less, which then allows you to scroll through that output as if it were a separate file.
来自 dmesg 的输出当做标准输入被重新传入到比较少量, 哪一个然后让你检视那输出好像它是一个分开的文件。

Standard output is just as easy to redirect.
标准的输出正如是当做容易的重新传入。

 For example, the following command uses the right redirection arrow (>)to send the standard output of the ls command to the file named filelist.
 举例来说,下列的指令使用正确的重定向箭 (>) 将 ls 指令的标准输出送到叫做 filelist 的文件。

# ls > filelist

You can add standard output to the end of an existing file with a double redirection arrow with a command such as ls >> filelist.
你能增加标准的输出为目的现有文件以一支两倍的重定向箭用一个指令,像是 ls>> filelist。

If you believe that a particular program is generating errors, redirect the error stream from it with a command like the following:
如果你相信一个特别的程序正在产生错误, 像下列各项一样重新传入有着一个指令的来自它的错误水流:

# program 2> err-list

热门下载

更多