1.4. Communication with Unix
Probably the single most important
concept for would-be power users to grasp is that you
don't "talk"
directly to the Unix operating system. Instead, you talk to a
program -- and
that program either talks to Unix itself or it talks to
another program that talks to Unix. (When we say
"talk" here, we mean communication
using a keyboard and a mouse.)
There are three general kinds of programs you'll
probably "talk" to:
-
The program called
the shell (Section 27.1). A shell is a command
interpreter. Its main job is to interpret the commands you
type and to run the programs you specify in your command lines. By
default, the shell reads commands from your tty
and arranges for other programs to write their results there. The
shell protects Unix from the user (and the user from Unix).
It's the main focus of this book (and the rest of
this article).
-
An interactive
command, running
"inside" a
tty, that reads what you type directly. These
take input directly from the user, without intervention from the
shell. The shell's only job is to start them up. A
text editor, a mail program, or almost any application program (such
as word processing) includes its own command interpreter with its own
rules. This book covers a few interactive commands -- such as the
vi editor -- but its main focus is the shell
and "noninteractive" utilities that
the shell coordinates to do what needs doing.
-
A Graphical User
Interface (GUI) with a desktop, windows, and so on. On Unix, a GUI is
implemented with a set of running programs (all of which talk to Unix
for you).
Unix was around long before GUIs were common, and
there's no need to use a GUI to use Unix.
In
fact, Unix started in the days of teletypes, those clattering
printing devices used to send telegrams. Unix terminals are still
referred to as teletypes or ttys
(Section 2.7).
The core of the Unix
operating system is referred to as the
kernel (Section 1.10). Usually, only
programs talk to the kernel (through system calls). Users talk to one of the
three previous types of programs, which interprets their commands and
either executes them directly or passes them on to other programs.
These programs may, in turn, request lower-level services from the
kernel.
Let's look at a specific example of using the shell.
When you type a command to display files whose four-character
filenames start with the letter
"m":
??? Section 1.13
% cat m???
it is the shell that finds the
filenames, makes a complete list of them, and calls the cat (Section 12.2) command to
print the expanded list. The cat command calls on
the kernel to find each file on the disk and print its contents as a
stream of characters on the display.
Why is this important? First of all, you can choose between several different shells (Section 1.6), each of which may have different rules for
interpreting command lines.
Second, the shell has to
interpret the command line you type and package it up for the command
you are calling. Because the shell reads the command line first,
it's important to understand just how the shell
changes what it reads.
For example, one basic rule is that
the shell uses "whitespace" (spaces
or tabs) to separate each
"argument" of a command. But
sometimes, you want the shell to interpret its arguments differently.
For example, if you are calling grep (Section 13.1), a program for searching through files for a
matching line of text, you might want to supply an entire phrase as a
single argument. The shell lets you do this by quoting (Section 27.12)
arguments. For example:
% grep "Power Tools" articles/*
Understanding how the shell interprets the command line, and when to
keep it from doing so, can be very important in a lot of special
cases, especially when dealing with wildcards (Section 1.13), like
the * (asterisk) in the previous example.
You
can think
of the relationship of the kernel, the shell, and various Unix
utilities and applications as looking like Figure 1-1.
Figure 1-1. Relationship of kernel, shell, utilities, and applications
Figure 1-1 shows that a user can interact with the
shell, as well as directly with interactive commands like
cat and ls. The shell transfers
control to the commands it starts for you -- then those commands
may write the output you see.
The
shell also has some built-in
commands (Section 1.9) that run directly
within the shell itself. All of the commands shown in Figure 1-1 interact directly with Unix itself.
--TOR and JP
 |  |  | 1.3. The Core of Unix |  | 1.5. Programs Are Designed to Work Together |
Copyright © 2003 O'Reilly & Associates. All rights reserved.
|
|