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

📄 0083-0086.html

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




<HTML>

<HEAD>

<TITLE>Sams Teach Yourself Linux in 24 Hours:Using the Shell:EarthWeb Inc.-</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=0672311623 //-->

<!-- TITLE=Sams Teach Yourself Linux in 24 Hours//-->

<!-- AUTHOR=Bill Ball//-->

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

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

<!-- CHAPTER=06 //-->

<!-- PAGES=0083-0102 //-->

<!-- UNASSIGNED1 //-->

<!-- UNASSIGNED2 //-->







<P><CENTER>

<a href="../ch05/0082-0082.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0087-0089.html">Next</A>

</CENTER></P>



<A NAME="PAGENUM-83"><P>Page 83</P></A>







<H3><A NAME="ch06_ 2">

Hour 6

</A></H3>



<H2>

<A NAME="ch06_ 3">

Using the Shell

</A>

</H2>



<P>In this hour you'll be introduced to the shell. Although the trend in

personal computing in the last 10 years has been to move away from the command

line to a point-and-click interface, the shell is still very much alive in Linux,

and is used by many Linux programs.

</P>



<P>This hour doesn't go into a detailed history of Linux or UNIX shells, or

take sides in a debate over which computing interface is easier or better to use.

Nor does this hour delve into shell programming&#151;there's also not enough

room in this hour (or even this book) to do so. This hour does, however,

discuss the different shells you'll find on your CD-ROM, show you how to use the

shell to make your Linux experience more enjoyable, and highlight some of

the basics of using the shell and its command line.

</P>



<H3><A NAME="ch06_ 4">

What Is a Shell?

</A></H3>



<P>If you're not using the X Window System, the shell is one of the

most important programs you'll use. The shell provides the interface to Linux so

you can run programs. In fact, the shell is just another Linux program. While

you can set up and run Linux without a shell (see Hour 20, &quot;Basic

System Administration,&quot; for details), you may find that you'll do a lot of typing at

the

</P>



<A NAME="PAGENUM-84"><P>Page 84</P></A>





<P>

shell's command line.

</P>



<P>The shell is a command-line interpreter, and may be used to start, suspend, stop, or

even write programs. The shell is an integral part of Linux, and is part of the design of

Linux and UNIX. If you imagine the Linux kernel as the center of a sphere, the shell is the

outer layer surrounding the kernel. When you pass commands from the shell, or other

programs, to Linux, the kernel (usually) responds appropriately.

</P>



<P>There are many types of shells, but at least five (not counting the visual shell

Midnight Commander) are on your CD-ROM. You can determine which shell you'll use when

you log in to Linux by either looking at the contents of the

/etc/passwd file, or by searching the file for your username. Look at the following example:

</P>



<!-- CODE SNIP //-->

<PRE>

# fgrep bball /etc/passwd

bball:OmB5tToB8fYLQ:500:500:William H. Ball,,,,:/home/bball:/bin/bash

</PRE>

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



<P>Your shell will be listed at the end of your

passwd file entry (/bin/bash in the fgrep search example).

</P>



<H3><A NAME="ch06_ 5">

What Shells Are Available?

</A></H3>



<P>This section lists the shells available for your system, along with some unique features

of each to get you started. Each of these shells runs programs, and you may want to

explore each to see how they work. This section highlights some of their differences and points

out important files.

</P>



<P>All of these shells support changing directories with a built-in cd, or

the change directory command. Interestingly, the ash and tcsh shells do not have a built-in

pwd, or print working directory commands, and must instead rely on the

pwd command found under the /bin directory.

</P>



<P>These shells have many, many features. You'll want to read the manual pages for each

in detail. Some of the features to look for and explore include the following:

</P>



<UL>

<LI>     What are the shell's built-in commands?

<LI>     How is job control (or background processes, discussed in a later

         section, &quot;Running Programs in the Background&quot;) handled?

<LI>     Does the shell support command-line editing?

<LI>     Does the shell support command-line history?

<LI>     What are the important startup or configuration files?

<LI>     What environmental variables are important for each shell?

<LI>     What command-line prompts may I use?

<LI>     What programming constructs are supported?

</UL>











<A NAME="PAGENUM-85"><P>Page 85</P></A>







<TABLE BGCOLOR=#FFFF99>

<TR><TD>JUST A MINUTE</TD></TR><TR><TD>

<BLOCKQUOTE>

There are several other shells that also are included with Linux: tclsh, a

simple shell and Tcl interpreter; wish, a windowing shell for X11; and rsh, a

remote shell for running commands over a network. For details, see the tclsh, wish,

and rsh manual pages.

</BLOCKQUOTE></TD></TR></TABLE>





<H4><A NAME="ch06_ 6">

Features of ash

</A></H4>



<P>The ash shell, by Kenneth Almquist, is one of the smallest shells available for Linux.

This shell has 24 different built-in commands, and 10 different command-line options. The

ash shell supports most of the common shell commands, such as

cd, along with most of the normal command-line operators (discussed in the later section, &quot;Understanding the

Shell Command Line&quot;).

</P>



<H4><A NAME="ch06_ 7">

Features of the Default Linux Shell&#151;bash

</A></H4>



<P>The bash, or Bourne Again SHell, by Brian Fox and Chet Ramey, is the default Red

Hat Linux shell. It features 48 built-in commands and a dozen command-line options. The

bash shell works just like the sh shell, and you'll find a symbolic link under the /bin

directory, called sh, that points to the bash shell.

</P>



<P>Not only does bash work like the sh shell, but it also has features of the csh and ksh

shells. Because this is the default shell, bash is used for the examples in this hour. Later on

you'll be shown how to customize your command-line prompt using the bash shell.

</P>



<P>The bash shell has many features. You can scroll through your previous commands

with the arrow keys, edit a command line, and if you forget the name of program, you can

even ask the shell for help by using command-line completion. You do this by typing part of

a command and then pressing the Tab key. For example, if you type l and press the Tab

key, you'd see the following:

</P>



<!-- CODE //-->

<PRE>

# l &lt;TAB&gt;

laser       less        listres     locale      look        lsac

last        lesskey     lkbib       localedef   lookbib     lsattr

lastb       let         lmorph      locate      lpq         lsc

latex       lex         ln          lockfile    lpr         lsl

lbxproxy    lha         lndir       logger      lprm        lynx

ld          lightning   loadkeys    login       lptest      lz

ld86        lisa        loadunimap  logname     ls

ldd         lispmtopgm  local       logout      lsa

</PRE>

<!-- END CODE //-->



<P>The bash shell responds by listing all known commands beginning with the letter l.

This can be very handy if you can't remember complex command names.

</P>



<A NAME="PAGENUM-86"><P>Page 86</P></A>





<P>

The bash shell also has built-in help, and lists all the built-in commands, as well as help

on each command. For example,

</P>



<!-- CODE //-->

<PRE>

#  help

GNU bash, version 1.14.7(1)

Shell commands that are defined internally.  Type `help' to see this list.

Type `help name' to find out more about the function `name'.

Use `info bash' to find out more about the shell in general.



A star (*) next to a name means that the command is disabled.



 %[DIGITS | WORD] [&amp;]               . filename

 :                                  [ arg... ]

 alias [ name[=value] ... ]         bg [job_spec]

 bind [-lvd] [-m keymap] [-f filena break [n]

 builtin [shell-builtin [arg ...]]  case WORD in [PATTERN [| PATTERN].

 cd [dir]                           command [-pVv] [command [arg ...]]

 continue [n]                       declare [-[frxi]] name[=value] ...

...

 while COMMANDS; do COMMANDS; done  { COMMANDS }

</PRE>

<!-- END CODE //-->



<P>To get help with a particular command, type the command name after the help

command. For example, to get help with help, type the following:

</P>



<!-- CODE //-->

<PRE>

# help help

help: help [pattern ...]

    Display helpful information about builtin commands.  If PATTERN is

    specified, gives detailed help on all commands matching PATTERN,

    otherwise a list of the builtins is printed.

</PRE>

<!-- END CODE //-->



<P>For more information about the bash shell, you'll find a manual page, info pages you

can browse with the info command, and documentation under the

/usr/doc directory.

</P>



<H4><A NAME="ch06_ 8">

The Public Domain Korn Shell&#151;ksh

</A></H4>



<P>The pdksh, or public-domain Korn shell, originally by Eric Gisin, features 42

built-in commands, and 20 command-line options. This shell is found under the

/bin directory, but a symbolic link also exists under the

/usr/bin directory.

</P>



<P>The pdksh shell is named ksh in your Linux system, and like the bash shell, reads the

shell initialization script /etc/profile if a file

called .profile does not exist in your home

directory. Unfortunately, this shell does not support the same command-line prompts as the

bash shell. However, this shell does support job control (discussed later this hour), so you

can suspend, background, recall, or kill programs from the command line.

</P>



<P>This shell is nearly compatible with commercial versions of the Korn shell included

with commercial UNIX distributions. Documentation for this shell is in the ksh manual

page, and in the pdksh directory under the

/usr/doc directory.

</P>



<P><CENTER>

<a href="../ch05/0082-0082.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0087-0089.html">Next</A>

</CENTER></P>











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

<!-- begin footer information -->









</body></html>

⌨️ 快捷键说明

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