-->

Previous | Table of Contents | Next

Page 83

Hour 6

Using the Shell

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.

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—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.

What Is a Shell?

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, "Basic System Administration," for details), you may find that you'll do a lot of typing at the

Page 84

shell's command line.

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.

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:


# fgrep bball /etc/passwd

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

Your shell will be listed at the end of your passwd file entry (/bin/bash in the fgrep search example).

What Shells Are Available?

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.

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.

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:

Page 85

JUST A MINUTE
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.

Features of ash

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, "Understanding the Shell Command Line").

Features of the Default Linux Shell—bash

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.

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.

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:


# l <TAB>

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

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.

Page 86

The bash shell also has built-in help, and lists all the built-in commands, as well as help on each command. For example,


#  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] [&]               . 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 }

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:


# 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.

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.

The Public Domain Korn Shell—ksh

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.

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.

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.

Previous | Table of Contents | Next