UNIX for people : a modular guide to the UNIX operating system : visual editing, document preparation, & other resources 0139374590, 9780139374593


780 124 26MB

English Pages 568 Year 1985

Report DMCA / Copyright

DOWNLOAD PDF FILE

Recommend Papers

UNIX for people : a modular guide to the UNIX operating system : visual editing, document preparation, & other resources
 0139374590, 9780139374593

  • 0 2 0
  • Like this paper and download? You can publish your own PDF file online for free in a few minutes! Sign Up
File loading please wait...
Citation preview

CltNiat PATHOLOGY SERVICE (113A) VA MEDICAL CENTER 4150 CLEMENT STREET

SAN FRANCISCO, CA 94121

,

v,\Cl'|

CUBICAL PATHOLOGY SERVICE (213V VA MEDICAL CENTER 4150 CLEMENT STREET SAN FRANCISCO, CA 94121

RECEIVE"' JUL

1

8 1985

Digitized by the Internet Archive in

2017 with funding from

Kahle/Austin Foundation

https://archive.org/details/unixforpeoplemodOObirn

UNIX A Modular

Guide

for People

to the

UNIX

Operating System:

Visual Editing, Document Preparation,

&

Other Resources

% *

%

i!:

' i'

i

t

*

I

I

^

-

q

UNIX ‘for A Modular

Guide

to the

People

UNIX

Operating System:

Visual Editing, Document Preparation,

Peter Patrick B.

M.

&

Other Resources

Birns

Brown

John C. C. Muster

Prentice-Hall, Inc., *

UNIX

is

a

Englewood

trademark

Cliffs, N.J.

of Bell Laboratories

07632

Library of Congress Cataloging in Publication Data

Bims.

Peter.

UNIX

for people.

Includes index. I.

UNIX (Computer

Patrick

U N

I

B

II.

operating system)

Muster. John C.

III.

I.

Title.

Brown. IV. Title:

X, for people.

OA76.6.B5725 1984 ISBN 0-13-937459-0 ISBN 0-13-937442-6 (pbk.)

UNIX

is

a

84-10678

()01.64'2

trademark of

Bell Laboratories

Editorial / production supervision: Barbara

H. Palumbo

Cover design: Celine Brandes, Photo Plus Art Manufacturing buyer: Anthony Caruso Page layout: Peggy Finnerty, Jill Packard, Toni Sterling Photographers: John C.C. Muster, Patrick B. Brown, Peter M. Birns Typesetting: Patrick B. Brown, Peter M. Birns, John C.C. Muster Illustrations: Kevin Daly and Dana Cuff

©1985 by

Peter

M.

Birns, Patrick B.

No

All rights reserx'ed.

Brown, and John C.C. Muster

part of this publication

may be

reproduced,

stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording, or otherwise, without

prior written permission of the publishers.

Printed in the United States of

10

9

8

ISBN:

7

6

5

4

3

America

2 ..

1

0-13-'t37MST-D

-13-T37MMB-b IPBK.I Prhntice-Hali. Internahonal. Inc., London

Prentice-Hall oe Austraita Pfy. Limited, Sydney Editora Prentice-Hall do Brasil, Ltda., Rio de Janeiro Prentice-Hall Canada

Inc., Toronto

Prentice- Hall of India Private Limited,

New

Delhi

Prentice-Hall of Japan, Inc., Tokyo Prentice-Hall of Southeast Asia Pie. Ltd., Singapore

Whitehall Books Limited,

Wellington,

New Zealand

D1

Contents

Foreword Preface

Hi

Introductory Modules One

How

Two

Accessing the

Three

Your

Four

Editing Files Using the Visual Editor

Five

Nroff Formatting

Six

File

Seven

Conceptual Overview

105

Eight

Advanced Visual Editor Commands

120

Nine

Advanced Formatting Commands The -ms Macros

142

Ten

A

to

Use This Book

UNIX

1

System

6 21

First File

Management

Stroll

Through

Commands with Shell

Commands

37 61 81

a

Full Production

Number

169

V

Modules Eleven

Twelve

The Line Editor Ex Special Search

177

and Substitution 203

Characters

\J

Thirteen

Truly Advanced Visual Editing

222

Fourteen

Communicating with Others

241

Fifteen

The UNIX Directory Structure

249

Sixteen

Account Management

272

Seventeen

Backgrounding

Eighteen

Parts

Nineteen

Phototypesetting with Troff

Twenty

Macro Construction

Twenty-One

Utility

Twenty-Two

Commands,

Activities

and Wholes

301

&

Troff -ms

Programs

355

and Directories: Paths, Bins, & Yellow Brick Modes Files,

Form

Twenty-Four

Special Formatting Topics:

&

A

Title Page,

Index

Twenty-Seven

404

A

Busboy’s Nightmare The TBL Pre-Processor

Setting Tables:

421

Equalizing Equations:

The EQN Pre-Processor Twenty-Eight

Troubleshooting

Twenty-Nine

Where

VI

392

Bibliographies and Footnotes:

The REFER Program Twenty-Six

366 382

Letters

Table of Contents,

\1

312 327

Twenty-Three

Twenty-Five

289

a Process

to

Now?

445

468 481

Command Summary

Section

Shell

488

Visual Editor

497

Format

.

507

Location of Material within the Book Index

518

Quick Access Chart

527

VII

aHr ‘•S*

€ t

}

i

4

«

t

V

•}

!?

n

Foreword

Why

Does Anyone Need a Book to Help Them Learn to Use UNIX? The UNIX computing environment enhances human pro-

No

ductivity. ity.

ing

other single reason can explain

its

growing popular-

Yet some would — be users have considerable how to use it, and others never learn to

Why

effectively.

is

this

so?

apocrypha nicely captures UNIX have

is

so

The

this

following

tap

power

its

of Bell Laboratories

paradox:

complicated

to teach the

bit

difficulty learn-

engineers

the

secretaries

how

to

use

it!

We

have observed similar activities in our own environments, so even if the quote is not a literal truth (and is a disservice to both secretaries and engineers), it is a useful illustration of the importance of the method by which one learns how to use UNIX, and learns how to use it effectively. The key here is that secretaries, and other people who need to use computers to get their work done, have the luxury of learning experientially — often in a supportive environment full of other users who have learned what they

know

in similar

fashion.

But there are problems with learning to use UNIX experientially. First, in the absence of a book like this, one must have access to the right kind of supportive environment, something difficult to find

outside

certain

institutions.

And

second,

the

experiential

It be self— limiting. is hard to develop, unilaterally, the requisite conceptual models which unlock the real power of the UNIX environment.

learning

Both

tends,

eventually,

experiential

One reason

to

learning and conceptual models are necessary.

analytically

inclined

would-be

engineers) have difficulty getting started ribly inefficient way of discovering the

is

users

(our maligned

that ‘‘analysis'’

skills

is

a ter-

necessary to be an L\

And

much

The problem with too much experiential learning is that, eventually, UNIX users come to the point where they enter a mere line of text and “mountains

effective

user.

move’*!

If

it

it’s

not

fun.

wasn’t the right collection of mountains, or they

didn’t go to the right place, experience rarely provides the explana-

here that an (analytical) model can help a user probe the process UNIX uses to execute his or her command, to reveal the source of the error. Lest the reader be intimidated by this, simple tion.

It’s

diagrams or a repertoire of well chosen examples can provide much of what is needed.

So most would — be UNIX users, especially ones who are learning how to use computers for the first time, need a good book — one that provides sufficient guidance for the experiential learning, and one which also helps consolidate the experience via the timely introduction of conceptual models.

Why UNIX.

This Book? It

This book addresses both barriers to learning provides guidance sufficient to allow computer — naive

users to learn

how

to use

so on their own, and

it

UNIX

experientially,

provides

how UNIX works, models

some of

necessary

for

even

if

they must do

the requisite models of

consolidation

of

the

The user “experiences” laid out fun and efficient. The experiences convey a

experientially acquired material.

by the authors are wealth of material, without seeming burdensome. Similarly, the models of editor— states, of the UNIX command interpreter, and of the hierarchical file system are clear, carefully pictorial, and essen-

They give the reader the confidence to engage moving with reasonable expectations for success.

tial!

in

mountain-

What Can Readers Expect To Be Able To Do Once They Complete It? Users who complete this book will be well on their way computing productivity. As the early focus is on word — processing and document preparation, readers begin getting real work done as soon as possible; and the exposition is sufficiently tool — oriented (again, tools are what one uses to get work done) so that readers will be able to learn to work in other arenas, such as program development and maintenance. The tool — building techniques illustrated are very general and are among the most powerful activities that UNIX facilitates. to

enhancing

their

Ultimately, the real power of

UNIX

methods it enables for getting work done with a computer. These methods are hard to articulate, computer scientists are struggling with them as we X

lies in

the

from examples. One of the strengths of this book is that its authors had to learn these methods, unconsciously, to complete their book. The book was a group effort resulting from the focus of different backgrounds on a single topic — how to teach people how to use UNIX. It has been field tested by students and staff, gone through numerous revisions and might never have been completed had it not been done using UNIX. Thus, the UNIX methodology is implicit in what the authors have done, and their real success is that they have communicated this experience to their readers. write,

but

they

can

be

learned

Mark

S.

Charles Michael

Tuttle

Woodson J.

Clancy

Computer Science Division

— EECS

University of California, Berkeley

March, 1984

XI

Preface

This book

UNIX. It was written over the span of two years, using a UNIX system. We began with the modest intention of providing our friends with some introductory, English language materials on how to text process with UNIX. It is a comment about the ability of the system to foster evolving group projects that our five page introduction grew into this book. One of Another modified and us wrote a few pages explaining how to. expanded the ideas. More was written, revised, combined, thrown out, synthesized, and rewritten— with the entire process taking place in one set of files in one UNIX account. is

a creature of

.

Our

desire

minimum

is

that

the

reader

of frustration learn

quickly,

how

to

.

efficiently,

and with

do what took us

a

collectively

over 10 years to discover concerning how to use UNIX. An understanding of the information presented here would allow you to create a product matching the detail and complexity of this book.

UNIX

is

a seductive beast.

We

several times, only to discover

mand, or had

a different

thought we had the text finished

some

way of looking

additional ideas, a at

new com-

the whole thing that just

be included. Because revisions are so easily accomplished with UNIX, we made the changes. to

What was

an introductory book on text processing and the visual editor (perhaps 200 pages at most) has grown into a more complete introduction to the entire UNIX Operating System. The expansion of our task was due largely to the feedback we received from students using drafts of the text in workshops and classes. Each group of students identified aspects of the system they wanted to know more about.

XU

originally intended as

We

computer

are not

educators.

We

scientists.

We

like

to

consider ourselves

selected and ordered the topics, wrote explanations,

and created conceptual maps with the goal of providing educationally sound, accessible material. Our objective was to remain truthful about how the system works and to present this information in an educationally effective way.

Three people— our respective partners — have made enormous con-

We

profoundly Without their support we could not have completed tributions

to

this

project.

are

in

this

their

debt.

book.

thousands who used this book in its various unpublished stages and gave us a chance to explore firsthand which parts of our efforts were effective and which needed additional work. Finally,

we

offer a sincere thanks to the cast of

Peter Patrick B.

M. Birns

Brown

John C. C. Muster University of California

Berkeley

'

V

# caog

Module One

How

to

wr

Use This Book

Introduction The UNIX operating system provides an effective and efficient way to compose papers, write computer programs, enter data, and maintain records. UNIX is a powerful system: there is virtually no what can be accomplished using and programs. Because it can do so much limit to

Due

its it

variety of is

commands

rather complicated.

complexity people have often found learning to use UNIX a frustrating and at times overwhelming experience. As a direct result of interacting with people as they learned UNIX and text processing we developed this modular, self-paced, ""low-jargon''' to

its

handbook.

Prerequisites None. It is assumed that the reader has no knowledge of computers, UNIX, or text processing.

Objectives The

objective of this

Module

is

to introduce

conventions and the modular format used effectively learn UNIX and text processing.

you

in this

to the essential

book so you can

1

The (a)

(b)

objectives of this

book

are the following:

Completion of Modules One through Ten will allow you to use the visual editor to prepare most research papers or reports and to enter and edit computer programs; Mastery of the individual Modules Eleven to Twenty-Nine will allow you to complete more advanced specific tasks, such as use special characters for searches and substitutions, send electronic messages to other UNIX users, create and easily

move among

several levels of directories, generate typeset

documents, access the UNIX preformatters which exist to help with bibliographies, equations, and tables, and write your own formatting commands (macros); and (c)

Completion prepare you

Modules One through Twenty-Nine will format a document or written project similar in

of to

complexity to

this

book.

Procedure (1)

Establishing an Account:

Make arrangements through your

super-

department, or system administrator for a UNIX account. Depending upon your location, you will need to obtain two or three pieces of information about your account:

visor,

(a)

you are located in a large organization in which there is a “network” of UNIX machines, you will be assigned to one of them and given a system name. You will need to know the name of the machine you are assigned. This information consists of a system name^ letter, or number,

(b)

Your account

(c)

Your account password.

If

login name',

and

Be certain you obtain the appropriate information about your account. Without this information you will not be able to gain access to UNIX.

(2)

2

How

People Learn:

has been our experience teaching courses and workshops in text processing that people: It

(a)

Learn

(b)

Learn best when they can about it;

Using

this

at different

Book

speeds; try

out each process as they read

(c)

Grasp ideas better

in

(d)

Remember more

effectively

self-contained units; if

they practice

commands and

procedures; (e)

Master complicated material most a “step by step” way; and

(f)

Better retain information

easily

when given

when

led

through

in

opportunities to review

recently learned material in self-diagnostic “quizzes.”

(3)

Using These Modules: Although we are firm believers in the educational value of getting lost and finding your way back home, UNIX can be a very unfriendly universe for someone who is off the path and unfamiliar with the rules. We suggest you allow us to hold your hand and lead you step by step through the basic procedures of the first ten Modules. Hundreds of people learning UNIX guided our design and revisions of the modular sequence and content of this book. You will find learning UNIX least frustrating if you study each section in order. Don’t skim over paragraphs, and be sure to try each procedure at least once. Avoid the pressure to hurry— relax and master each part. (a)

Each Module

(b)

Following the Introduction is a list of Prerequisites. you satisfy each prerequisite before proceeding.

(c)

The do

(d)

starts with a brief Introduction to set the stage.

you know what you completing each Module.

Objectives section lets

after

The Procedure

section

is

a

step by step

list

will

Make

sure

be able to

of actions you

should take and explanations you should read. (e)

Exercises,

reviews and self-check questions are an integral

part of the procedures.

Taking the time

them

ability to

will

improve your

you may surprise yourself with (f)

(g)

to

perform or answer

remember the material (and what you know how to do).

You

will

The

following conventions are used throughout this book.

be asked to type in text as you proceed through the book. Don’t begin learning text processing with a paper or other written material that is important to you! Practice with something you can afford to lose.

All

UNIX commands

are in boldface type.

When you

Using

this

are to

Book

3

supply information to a command sequence (such as your own password) the requested word\ will be put inside a box |

(h)

\

Be patient with yourself. There it

can be frustrating, but

it

is

a lot to learn

can be mastered.

about UNIX —

You

are better

few extra moments reviewing each section than rushing through the process. off taking a

(i)

(This

“types” in the crowd.) This book was written to be used with Bell Lab’s UNIX Version 7 with Berkeley enhancements (BSD UNIX). This material should be of use for instruction about any UNIX system that supports is

for the technical

the visual editor “vi.” currently available

— in

Due

many versions of UNIX to the many local variations in be some slight differences the

to

addition

implementation — there may between the procedures you should use and those presented in this book. These variations will be most pronounced when getting started or accessing the

UNIX system.

If so,

ask for

help getting “logged in.” (j)

We

have made every effort to insure that all suggestions are appropriate and command sequences correct. We have been through several drafts of these materials— and thousands of students have worked with many of the Modules — to eliminate errors and problems. Please be aware, however, that the sophistication and complexity of the UNIX Operating

System— coupled



with the various versions in use make the task of completely “bomb proofing” your experience essentially impossible. Before attempting to use a new procedure with your version of the Great American Novel or Nobel Prize-winning report you should first experiment with a prac-

Only then can you feel comfortable that the command or procedure will do what you want it to do. tice

(4)

file.

might be helpful (but is not necessary) to identify an experienced UNIX user (most college campuses have paid computer conIt

sultants, while in a business or office setting there will be familiar with the local UNIX system). Inform this

someone

individual of

your intention which logging

Two

4

to learn

UNIX with the help of

steps outlined in the are appropriate for your location.

Using

this

in

Book

first

book, and ask few pages of Module this

(5)

Modules One through Ten comprise the foundational core of the book and should be studied in the order presented. Each builds upon skills mastered in prior Modules. Modules Eleven to Twenty-Nine can be taken in any order, as long as all prerequisites are satisfied.

(6)

Proceed to Module

Two and

enjoy the learning process.

R,kett,

hungry

dtcides to

mr jmmortcdii/, ujrite his

autohiogruphy on the ^^processor.

Using

this

Book

5

Module Two Accessing the

UNIX System

Introduction In this

work

Module you

will

learn

how

to access

(logon) and finish

on your UNIX account. Four commands the kind of resources available on UNIX.

(logout)

to illustrate

will

be used

Prerequisites

You need through

to

have

a

UNIX account. An account can be established

contacting

administrator.

your

supervisor,

Depending upon your

department,

or

system

you will receive one, two, or three pieces of information about your account. If you are in a large organization in which there are several UNIX systems you will be assigned to one of them and given (a) a system name. At all locations you will be given (b) a login, a short name that the computer and you will use to identify your work. Most locations will also provide you with (c) a secret code password, which is used to protect access to your account. Before beginning this Module enter this information

in pencil in

(a)

My

system

(b)

My

login

(c)

My

password

Accessing the System

is:

_

is:

is:

location

the spaces provided here:

Although your login name will be available to anyone interested, your password should remain secret so that only you can access your account. Your password is like your instant cash bank card “secret” code number which is known only to you and the bank.

Objectives

# coos

After completing this

Module you should be

able to: tnr

(1)

Identify yourself to

UNIX and inform

it

you are beginning

work (logon); (2)

Inform UNIX you are quitting work (logout); and

(3)

Make

use of the UNIX of

commands

who

(a)

Present a

(b)

Give today’s date and time;

(c)

Provide a

(d)

Change

list

list

is

which:

currently logged in;

of correctly spelled words; and

the password to your account.

Procedure Module Two contains four sections. First you will learn how to logon and logout of your UNIX account. In the second section the Conceptual

Four basic

Map of the logging on and out process is discussed. commands will be used in the third section to illustrate The

the kind of resources available in UNIX.

final section consists

of a review of the material presented in this Module.

Logging onto UNIX: Gaining Access

to the

System

Many

people have found that logging onto UNIX for the first time can be a very frustrating experience. If you have not already done so, it might be useful to identify an experienced UNIX user in your

and ask which parts of the logging in procedures outthis Module are appropriate for your location.

institution

lined in

Accessing the System

1

may

Additionally, you

number of each (1)

activity

START, Turning (a)

this

find

helpful to put a check next to the

it

once you’ve completed

the Terminal

it.

ON:

Turn on the power to the terminal. On many terminals switch is located on the back, lower right. The terminal

may answer

with a beep.

Wait a few seconds.

(b)

Find the brightness dial— usually located either just above the top right of the keyboard or on the back, lower right near the power switch. Adjust the brightness of the screen to a comfortable level.

(c)

you are were given If

in a location

with several UNIX systems (and you

system name) you might have a small box with a switch or button attached to your terminal. a

your terminal has such a switch or button, push without a button, skip this Step and proceed. If

is

If you

make an

it

— if

it

any point in the logging in procedure you should turn the power to your terminal off and then back on and begin again.

(2)

error at

Locate Map A at the end of this Module. Two copies are included in this text. We suggest you remove one copy to place next to your terminal for easy reference as you proceed through this material.

We

will refer

to

Map A

throughout the next few

pages.

The

in— as pictured Mode. Once you are

objective of logging

box labeled Shell mands to perform such and print material.

in

to get to the

you can enter comtext, look up spellings,

there,

activities as edit

In the process of getting to the Shell

Map A — is

you may be stopped and

asked for from one to four different pieces of information, depending on how your system is organized. You may be asked only for your login (account name), or you may be asked for login, password, system name and even for the name of the type of terminal you are using.

Map A

is

a sketch of the trip

arrival in the Shell.

8

Accessing the System

from turning the terminal on

Consider yourself to be

at

to

the beginning of

Map A down

at

the

the place labeled Start.

path toward the Shell.

Now

imagine yourself traveling Map A we have indicated

On

between turning the terminal on and the Shell. If your system needs information corresponding to one of the stations, you are stopped at that station and asked for the appropriate information. Once you type in the needed information you are allowed to go on.- If information at a station is not needed, you are not stopped but passed on to the next station.

the four stations that

(3)

lie

System Name: If the word Request: appears on the The printing of screen, you have been stopped at Station 1. that you indicates Request: Station

1,

have the machine’s attention and it needs to be told your or letter, name, system number.

Type the number, or

name

UNIX

(lower case)

you

of the

were entered by

you

system

assigned [Item

letter,

(a)

in the Prerequisites section

above].

Press

the

RETURN

key.

your system name does not appear on the screen as you type it, you should push the button or turn the power to the terminal off and back on. Once Request: reappears, re-type your system name. You must enter the letter (s) of your assigned system within 15 If

seconds of the appearance of the word Request: or else the computer will not attend to your response.

Feeling

Depressed?

If

the

machine

upper case characters check that the not

locked

depressed

on.

Make

(perhaps

certain

administer

presenting

ALPHALOCK

that .5

is

mg

this

key

all

key is

of lithium)

is

not

by

ALPHALOCK

key to release it. Next re-start the logging in sequence by pressing the button or turning the power to your terminal off and back on. pressing the

Accessing the System

9

(4)

Station

Login Name: The

2,

printing of login: indicates that

you have been stopped at Station 2, and the machine is ready to receive your login name.

Type [Item

(5)

(b)

your in

login

name

Prerequisites.]

certain

to

use

letters

or

numbers,

spaces.

Press the

all

lower

case

with

RETURN

Be no

key.

Station 3, Secret Password: If the word Password: appears on the screen, you have been stopped at Station 4. You will not be allowed to go any further without entering the password that is associated with your account.

Enter

your

password (again, leave no spaces), and press

RETURN.

As you

type your password

it

on the screen, so that no one else can see what it is. It is, however, being registered by the computer. (A few seconds will will

not appear

now

pass.)

Error in Logging On:

your login or password was entered incorrectly the terminal says login incorrect and repeats the word login:. You must then re-enter both the login and password. Be very careful to enter both exactly as provided you. Remember to use all lower case letters or numbers with no spaces, and to press

RETURN

If either

after entering each.

(Note that if you make a mistake entering the password., you will be told login incorrect and you must properly enter both the login and password.) both the login and password were correctly typed and match with the computer s list of accounts, you are permitted to continue If

down

the path.

the screen

10

may

Depending on how your or

may

Accessing the System

not begin

filling

local

system

is

managed,

with dated news items.

1

(6)

Station 4, Terminal Type: If your terminal displays the words TERM = Terminal Type?\ you have been stopped at Station 4.

UNIX must be informed what type of terminal you are using. This will allow UNIX and your terminal to communicate without any misunderstandings. (Pardon my dialect, but I’m from the Bronx.) In the

most straightforward case UNIX will be informed automatically about what type of terminal you are using, and you will pass by this Station.

you are stopped at Station 4, your screen will probably display line that looks something like one of the following: If

TERM =

a

(tvi925)

or:

TERM = The

(z29):

parentheses are an abbreviation for the most comterminal at your location (e.g., tvi925 for Televideo 925 or

letters in

mon

You

need to determine whether you are using the type of terminal mentioned in the above line (inspect the terminal for a nameplate and/or ask someone near you).

z29 for Zenith 29.

If

the terminal

RETURN If

is

will

of the displayed type you need only press the

key.

the terminal

is

a different type,

determine the appropriate

abbreviation and carefully enter it then press knows what type of terminal you are using.

(7)

RETURN. UNIX now

you entered a terminal type that UNIX recognized, a Shell Prompt % appears on the screen (this should take a few seconds). Note: Alternate versions of UNIX use different characters ( %, $, or #) Whenever we display a Shell prompt in this

The Shell Mode:

book we

will

If

use the

%

Prompt, you have made

sign. it

When

the terminal displays the Shell

to the Shell.

Accessing the System

1

(8)

Logging Out: The appearance of the prompt means you have completed the login procedure and the computer is waiting for your next instructions.

You now know how

to log

munication with UNIX)

is

onto UNIX.

much

Logging out (ending com-

simpler.

Logout of UNIX by typing the command logout

and press RETURN. This command tells UNIX you are finished working on your account and want to terminate this session.

you were successful, one of several things probably occurred. Either the screen went blank or the screen displayed a written mes-

If

sage like ‘‘logout complete.”

you are not logged out and the terminal displays the words Command not found you probably mistyped the word logout. Retype the command logout and press the RETURN key. If

Conceptual

Map

As an aid to your understanding of how the UNIX system operates, we will be introducing a series of “Conceptual Maps.” Each Map present those segments and paths of the system with which you are working. You have been using Map A to logon to the system. will visually

(1)

Map later

Symbols: To utilize the rest of Map A and the other Maps in Modules, you need to know what the various symbols mean:

(a)

The boxes and

“locations” in UNIX and contain both a descriptive label for the part of the UNIX system being accessed and the function performed by that part of the system.

(b)

The arrows

circles are

reflect

commands used

to

used

when you

move from one

place to

another. (c)

12

The symbol

®

is

Accessing the System

to indicate

are to press the

RETURN

key (right-middle of most keyboards).

tion will be used throughout this

RETURN

Now

book

The

®

nota-

to indicate Press the

key.

you have logged out, log back in following your path on the Conceptual Map. Notice how the information you type (system, login, password) moves you from one location (Station) that

to the next.

logged on, logout. Repeat the logging in and logging out procedure until you feel comfortable with both processes.

Once

fully

Logout of your UNIX account and continue reading Module.

Do

not forget

to

logout

whenever you

UNIX session — if you neglect

this

are finished with a

your account will continue to accrue the hourly connection charge. In addition, some unscrupulous, dastardly, or generally ornery critter may discover your oversight and proceed to first use your account to perform his/her own UNIX tasks, then delete all your files and send nasty notes to your friends, thereby causing you untold grief and probably leaving you freight train

first

In

summary: be

little if

to logout,

choice but to leave town on the

you are even remotely honorable.

certain

you logout

after

each UNIX ses-

sion.

Four Shell Commands The appearance of the Shell Prompt % indicates “Shell Mode,” the main command center of (Find the box marked Shell on Map A.) Being that

you can issue

programmed

to

you are in the the UNIX system.

that

in

the Shell

means

a specific set of

commands which

The commands.

following procedure steps intro-

respond

duce four of these

to.

the machine

is

Each of these four resources can be accessed only from the Shell

Mode Mode

is

%

#

This is because the Shell programmed to perform a specific function in response to

(with the

or $ or

prompt).

Accessing the System

13

your entering each of these commands. The appropriate command is typed in and then the RETURN key is pressed. Until you press the the machine does not process what you have typed. Rather, it

®

®

you to indicate that you are finished typing instructions (which you do by pressing the RETURN key). Within quietly waiting for

sits

the Shell

Mode,

®

pressing the

key

is

interpreted to

mean “pro-

cess this line.”

(1)

Follow the Conceptual Map and log onto your account. If necessary, review the steps indicated in the prior section. Once you are logged in, and the Shell prompt is displayed, proceed to the next step. Note:

if

note “Command Try it again.

(2)

Who

one of the next commands you receive the not found” you probably mistyped the command.

after entering

on the System?

is

You

can request of UNIX a (what logins) are currently logged onto the system.

To

access this

command from

A

® as

of

who

the Shell type:

who Remember:

list

®

used above means press

the

RETURN

key.

of current users allows you to see if any of your friends are on the system and what terminal locations they are using. This list

prove useful once you learn how to communicate with them via UNIX. Notice that your login is included among the will later

several that are presented.

Two-Way Commands: Find the Shell on Map A. Locate command just used. Note that it is attached to an arrow

the

who

that has

heads on both ends (a two-way arrow). A two-way arrow with a command next to it indicates that by typing in the command you cause the computer to execute that command and then automatireturn you to the original mode. For instance, the command who is given from the Shell and will access the who system file. After performing its function (listing the logins of everyone logged onto the system) it will return you to the Shell Mode (your originating mode). cally

14

Accessing the System

(3)

What Time

Should you awake one day, forget to strap on your $7900 Rolex day-date wristwatch, log onto your UNIX account, and desire to know the current time and date, UNIX can Is It?

provide this information.

To determine

today’s date and time type:

date

(4)

How Do You

Spell

As

example

®

UNIX maintains an on-line spelling dictionary with a word volume somewhere between Webster’s elementary school version and the New Oxford Dictionary.

how ary

an

When

the

.

?

of

the

following.

prompt

Shell

appears type:

®

look egg

A

list

of

eggplant,

egghead,

egg,

most cases

In

word you might

the

know how

contained (the

be

will

etc.

displayed.

to

.

to access this dictiontry

%

.

to

the

in

like

spell

is

display

UNIX dictionary does

not contain definitions to

words, only the spellings).

You

enter the

first

few

of a word and UNIX displays

letters

all

the

words contained in its dictionary which begin with these first few Another example probably best explains how this works. letters.

The command

®

look psych

whole

ogy’.

produce Try this

that

amuses you.

will

The words porarily

a

command

will

halt

at a

rapid rate.

presentation

and psycholfew letters of a word

like psychologist,

again, using the

parade by

the

words

flock of

first

If

of words

you would press

temthe CTRL-S key like to

Accessing the System

15

down

marked CTRL and press the s key one time). Scrolling resumes when you press the SPACEBAR. (hold

(5)

the

key

Password: We have noted the importance of a password your keeping

My

Change

secret.

One

solution

is

to

never write it down. The only problem with not having it written

down anywhere

is

that

can be forgotten, especially

it

account

is

a

if

the password assigned to your

nonsense collection of random

letters.

one was not provided you, create one) to a “word” that does hold meaning to you. Your new password must be between five (5) and eight (8) characters in length, and should contain at least one letter and one number. Be careful to select a password that is not obvious: computer theft occurs with disturbing frequency. An obvious password provides no protection from any account snoopers who may inhabit your system. For instance, your birth date or the name of a spouse may not be good choices. A better choice would be some combination of several meaningful words {ml8ml8 if you like rabbits, or lOsnel if tennis is your hobby).

You

can easily change your password

To change your password

(or, if

type (from the Shell):

passwd After typing the passwd (a)

To supply your

(b)

To

type a

(c)

To

repeat your

command UNIX

® will

ask you:

old password;

new password; and

new password.

Be sure to remember the new password, as it will be your UNIX password from now until the next time you change it.

16

Accessing the System

A Note on Making It

is

easy to

make

Corrections

corrections within a single line because the Shell

does not process the line until you press the RETURN key. If you make an error in a line you may back up one or more characters by using the CONTROL-H key. Hold down the CTRL key and press the h key one time for every space you want to back up. If your terminal has a BACKSPACE key it may be used to accomplish the same thing. The characters can then be retyped.

Once you

press

RETURN

the line

is

“processed.’’

®

dote (typed incorrectly), then backspace

and

retype the correct Shell If

you experience

a

not

UNIX will then press found” and display another Shell prompt. Type the “word”

you mistype

“Command

command and

(1)

If

command

difficulty

reply

date.

using the

CTRL-H

or

BACKSPACE keys

does not backspace or the terminal beeps whenever you press these keys) you probably made an error when informing UNIX of the type of terminal you are using. Please see the section of Module Twenty-Eight: Trouble Shooting entitled Specifying Your Terminal Type. (perhaps

the

cursor

The Finale Without referring to prior sections of form the following actions:

this

Module

(a)

Logout of your account and turn the terminal

(b)

Log back onto your account.

(c)

Ask UNIX

Map

per-

off.

words

starting with the

Logout of your account and turn the power

to the terminal

to look

following letters: (d)

or the

up the spelling of

all

electr

off.

Accessing the System

17

When you

can perform the above actions without referring to sec-

tions of this

Module you have mastered

UNIX account. You files,

are

now

the ability to access your

ready to learn

which just conveniently happens

to

how

to create

your

be the content of Module

Three.

A PDP

18

11-70;

UNIX was

Accessing the System

own

originally designed to

run on

this

machine.

A

second copy of this

map

is

located at the end of the book.

Accessing the System

19

kJ-«

Module Three

Your

First File CDO

wr

3



Introduction In this

Module you

“file.”

A file

be using two important components of the UNIX system — the Shell and the Visual Text Editor vi—io create a is

will

the term used for a collection of characters that

stored together, such as the words in a letter or a paper, a

program, or a listing of data. together so you and UNIX can puter

work on

The

file

is

comkept

it.

generating process

often confusing at ing.

This information

is

Take

heart:

first

You

is

meet-

are not

Shell

know all about the and vi when you finish

this

Module.

expected to

Rather,

it

is

intended that you will gain experience you can build on in later Modules to understand the UNIX system.

Prerequisites His

You need

know how

first file.

your account (logon) and terminate work on the account (logout). If you are not sure how to accomplish these procedures, review Module Two. to

to access

21

Objectives Upon completion

Module you should be

of this

(1)

Create a

(2)

Append

(3)

Escape from Text Append Mode;

(4)

Quit working on a file, save the changes return to the Shell;

(5)

Display a

(6)

Have

file

for visual editing;

text to the

list

of

file;

all files

copy of your

a

able to:

in

file

made

in

the

file,

and

your account; and

sent to the printer.

Procedure The Procedure

Module

section of this

is

two

in

parts.

The

first

you through the process of creating and appending text to a file. The second section introduces the Shell commands to list the filenames in your account and to print a file. A brief self-quiz and a comprehensive command summary are placed at the end of this Module. A second Conceptual Map is included to help you chart your course through the paths of UNIX. section leads

Creating a

Appending

File,

Returning

Locate

(1)

Map B

again been included.

at

Text,

to the Shell

the end of this

Module— two

You should remove one and

your terminal to review as you complete your

Logon

(2)

learned in

to

it

22

is

First File

place

it

next to

activities.

logged on you are in the Shell prompt). Find this Mode on Map B; fully

(which usually has a % your home base in the UNIX

Your

copies have

your UNIX account following the procedure you

Module Two. Once

Mode

and

game of Hide and

Seek.

(3)

Starting Your First File: There are two steps to beginning your first file:

From

(a)

the Shell enter the following two words (which

must be

separated by a space): vi first space

I

Press the

(b)

RETURN

key.

Once you have entered the command sequence the

RETURN

key the screen

bottom of the screen saying “first"

New file.

Tildes

(~)

will clear

and a note

either “first'' will

vi first

No

will

and pressed

appear

the

at

such file or directory or

parade in a column

down

the

left,

Line numbers may also appear along the left border of the screen. This translates as: “OK, you’ve called for the file with the name./zrsr. It did not exist but is now being created and, at this moment, con-

and the cursor

tains

will

appear

at

left

of the screen.

no text.” you have

Let’s take a look at what

sequence (a)

the top

vi

vi first

means

is

that

in

two

just done.

The command

parts:

you wish

to

employ the UNIX y\sual

text editor,

and (b)

first is

the nanie of the

to be

worked on.

word you choose, within some limibe discussed later. (We are suggesting you title

The filename can be any tations that will

file

single

this hit first because, curiously,

it

is

your

® command

first file.)

on Map

The filename is in a box to indicate that you can substitute the name of whatever file In this instance, you have named this file you want for [filename} first. Recall also that ® included at the end of a command means Locate the vi

[filename}

B.

.

press the

RETURN

key after you enter the

command

sequence.

From Map B note that the command sequence vi moves you from the Shell to the vi Command Mode.

(4)

filename

®

Appending Text: “How can I add text to this file?” you ask. Although there are several ways to add text, we’d like to initially introduce one of the most useful commands. Your

First File

23

You

are in the Visual Editor

you want

tor that

not press the

Command Mode. To

to enter text, press this

RETURN

inform the edikey a single time (and do

key):

a

What happened? Nothing. How come this a didn’t appear on the screen? Because in the Command Mode, pressing the a key tells you want

add or append text to the file. After pressing the a key the visual editor will add anything you type to the file and at the same time display it on the screen. You are now in what is called Append Mode, because everything you type will be entered as text. vi

that

to

Type the following sentence:

(5)

/ anticipate a long

(6)

and harmonious

relationship with

UNIX.

Typing Suggestions:

PLEASE more

read this

we’d

typing, as

BEFORE

you begin any

like to

offer a couple of very important hints.

Short lines are most easily

worked with when using UNIX. You should press the RETURN key after each main idea or 5-8 words, and always after the end of each sentence. (Just like these lines.)

make

will

It

Your

editing

a

easier.

text should look like this section:

short lines, with

on

much

new

all

sentences starting

line.

After your text

is

formatted

(Module Five), the short lines will be joined together

form

uniform length. (Like the remainder of this text.)

to

lines of

Now

type the 16 short lines of text contained in Procedure Step 6 above. This is for practice, so don’t worry about mistakes.

24

Your

First File

Leave the typing errors alone— in a later Module you’ll learn how Just blast in the text. Don't bother with to easily correct them. corrections— ]\xsi type a line, press press

®

.

.

.

of text began

You

gin.

at

the

all

lines

left

mar-

of formatting will

that

specific

commands which

meet

in

Module

Five.

time you

will

insert

commands

to

indent

paragraphs, double space, and center

Whenever you

lines.

CSh^t

in

another

line,

text

you

should

not

attempt to format the material yourself— let UNIX do it for

lines are

most

easily

worked with when using UNIX.

You should after

press the

RETURN

keyj

each main idea

or 5-8 words, and

always after the end of each sentence. (Just like these tines.) It

enter

then type

did not indent para-

graphs or try to center lines or double space while typing in the text. UNIX possesses a set

you At

,

.

Note how

Finished?

®

will

Your

make

editing

much

easier.

text should look like this

section;

you.

(8)

Leaving the Append Mode: At this point you should now have 15 to 20 lines of text displayed on the screen before you. How do you now tell UNIX that you are finished adding text and want to do something else? Try typing these words: stop, finish,

getmeoutojhere, and pleaseletgoofmeiwantoutofthisthing

None of these words will move you out of the Append Mode (which you entered when you pressed the a key). You are finished, but everything you type continues to be What entered into the file.

you must do

is

tell

stop, finish, getmeoutofhere,

pleaseletgoofmeiwantoutofthisthing

the visual

move you out Append Mode and back to

editor editor to

of

Command Mode.

Your

First File

25

(9)

that

Look at Map B. What is the command written on the arrow moves you from Append Mode back to vi Command Mode?

THE WAY OUT OF APPEND MODE IS THROUGH PRESSING THE ESCAPE\y^ KEY your best vi friend — find it on the keyboard (usually near the top on the left), introduce yourself, and then gently, lovingly press it. Anything happen? Nothing appeared to happen, but you are now out of Append Mode and back in the Command

The

key

|ESC|

is

Mode. To be sounds,

certain, press the

[Em

key

a

second time.

If a

beep

simply telling you that you are already in Command Mode. Let us stress this point. In your trials and tribulations experienced while learning to use the visual editor you may find yourself a bit lost. While in the midst of entering text into a file VI

is

you may not be sure whether you are Mode. The ESCAPE key

When Mode

in

Mode

the

is

in

Command

or

Append

your path out of this confusion.

doubt about whether you are in vi Command or Append press the |ESC| key. Within the Append Mode the [esc key means. Move me into Command Mode.” Within the Command

ESC key means, ^Please beep.” When using the visual editor pressing the |esc| key will always leave you in Command Mode. You can decide from that point what it is you want to do. Trace the action you just now completed on Map B. Notice that the ESCAPE [ESC! key moved you out of Append Mode and back to Command Mode. Please review the information presented above. Knowing when to use the |£SC| key is the single most critical factor leading to successful editing with the visual editor.

(

10 )

__ Did

To it

insure you are in the Command Mode, press the lEsc] key. beep at you? The beep translates as, ”But Captain, you are

already in

From

Command Mode.” the

Command Mode

type this word:

duty 26

Your First File

What happened? The times, in fact.

(If

it

terminal should have beeped at you; several did not beep and the word duty appeared on

the screen, press ESC] and repeat this step.) !

Type the following:

(12)

aduty This time the word duty should appear on the screen. It appears because the first letter of the “word” aduty- was a and this a is the

append command. Therefore the a was interpreted to mean, “Move me from Command Mode into the Append Mode.” Thus, when you typed the next four letters they were entered into your file as text.

duty

Press the jESCj key.

(13)

You have

You

are returned to the

Command Mode.

had another real-life encounter with the a (append) and jESCj (escape) commands. just

Summary:

the a

command

text; the jESCj stops the

to

permits you to start entering

append process and returns you

Command Mode.

you have entered is now sitting on the screen staring at you and waiting for you to do something with it. Suppose you want to finish working on the file for nowleaving any typing mistakes you made in composing it uncorrected until later. You need a command which will tell the visual editor “Tm finished — save this text in a file for another time and bring me back to the Shell.” Looking at the Conceptual Map, what command moves you from v/ Command Mode back to the Shell?

(14) Returning to the Shell:

Go

The

text

ahead now and type (Upper Case):

ZZ If

the letters

Mode.

ZZ

appear on the screen you are

You must

first

move

to

in

still

Command Mode

Append this com-

the

for

mand to be properly interpreted. Press jESCj to move to the Command Mode and then type the ZZ command (hold the SHIFT key down and press the Z key two times). Your

First File

27

What happened? something

At the bottom of the screen appears the note

like:

'‘first*'

Below

20

lines,

the Shell prompt

568

characters.

%

which indicates you are back in the Shell Mode and that the system is awaiting your next Shell command (remember the Shell commands who, date, look, and passwd practiced in Module Two?). this

is

Examine

Ma p

y ou are in the Shell and enter the vi [filename\ you are moved into the ComB,

If

command ® mand Mode. The ZZ command moves you out of Command Mode and back to the Shell, and can only be executed when you are in the Command Mode (and not Append So a

(15)

or Shell

Mode).

you’ve written 15-20 lines of text and saved this material as named first (where it will wait patiently for your return.)

far

file

A

Second File: It would now be useful to through which you created your first file.

From

the Shell type the following:

second

VI \

As

practice the procedures

space

we put second in a box to indicate that you need not new file by the name second, but can use whatever name

before,

call this

you want. Trace the action you just completed on

row leading ind icates

into the

vi

Command Mode

Map is

a

Note that the arone-way arrow. This B.

from the time you enter the command vi \filename\ until you return to the Shell Mode, you are in ‘‘different world” where a different “language” is spoken. The t

hat,

commands

that the Shell can interpret cannot be understood by the visual editor, nor can the Shell properly interpret commands

meant

for the visual editor.

The commands

that are properly in-

terpreted by the Shell will be either misinterpreted or entirely not understood by the visual editor. Each Mode has its owm com-

mands.

28

Your

First File

(a)

In

what UNIX

Mode must you

be to use the vi second com-

mand?

(16)

(b)

After you enter the vi second you located?

(c)

What

Answers:

be the

will

(a) Shell

To append

(b)

name

of this

new

Command Mode

(add) text to the

must you enter? Press

command,

this

file

in

you are creating?

second

(c)

called second

file

what mode are

command

what

key (lower case): a

Again look at the Conceptual Map. (17) to what mode?

Answer: You

Now

are in the

Append Mode,

you are

that

in the

Pressing the a key

so text can

now

Append Mode,

be added to the

Write anything you want, but remember short and start all new sentences on new lines.

keep your

to

you should

6 to 8 lines,

are finished appending text, want this text saved in a to return to the Shell.

move

Refer to

Map

B;

is

from Append Mode to the Shell? reach the Shell you need to move in two steps:

From Append Mode

(b)

From

the

to

Command Mode;

Command Mode

lines

you and want

tell

file,

there a

directly

(a)

file.

type 6 to 8 short lines

of text.

Once you have entered these

moves you

vi

command

No.

to

In order to

and then

to the Shell.

You have been adding text, so at the moment you are in the Append Mode. Map B shows the command to move out of Append Mode and into Command Mode. It is the ESCAPE key.

Press:

Esc

You

are

now

in

the

Command Mode.

Your

First File

29

^

How

(18)

Map B

do you move from

indicates that

ZZ

Command Mode

the appropriate

is

to the Shell?

Again,

command. Type:

ZZ You should now be back

ZZ

appeared on the screen, you forgot to press the |ESC| key before the ZZ was the Shell.

at

(If

the

entered.)

Listing

Two more commands and (1)

and

Printing Files

Listing Files: Suppose you want to

your UNIX account. list)

Type the

Shell

know

The command

of the names of your

Is

the

names of

the

will call forth a list

files in {Is



files.

command:

®

Is

Did the filenames

Module Three.

you’re finished with

and second appear? The names of other files will also appear if you have created any others, or if your account is used by other people. The list command will work only from the Shell.

(2)

first

Line Printing Files: You might now like to produce a printed copy of one of your files. Look at Map B. Wh at comma nd is on the arrow from the Shell to the printer? The [filenam^ in the com-

mand any

Ipr [filename\

file

To

®

means

that

you can substitute the name of

you want printed. print out the

file first

you should

type:

first I

The

line printer {Ipr

Mne

space

printer)

command

is

only understood

by the Shell. For the terminally curious, the term line printer is derived from the fact that most early high speed printers printed one line of output at a time.

30

Your First File

You

can also send the

second to be printed with the

file

Ipr

second

command:

®

your printer is located away from your terminal.) Several moments after you have entered the Ipr [filenanw\ command sequence a message may appear on the screen informing you where your printed output (here, a copy of your file./7>5r) may be found. (This next point

is

relevant only

if

®

(If

(3)

down the name of box number displayed on the

appropriate) Write

number, and the need each to identify the

You

(4)

are

now

Module Three.

room you may

the building, screen, as

location of your printout.

finished with the on-line activities contained in

Logout of UNIX (from the Shell type the word

logout) and continue reading the last section.

You 've

Made

It

(Puff-Puff)

Module you are now text proCertainly there is much more to learn (otherwise we cessing. wouldn’t have written the next 400+ pages). Still, the fundamentals are contained in this section, and you’ll build on them in later With the knowledge gained

in this

Modules.

A summary text of this

A Quick

list

of the

Self-Quiz: Consider yourself finished with this Module

In

(b)

What must you

(e)

these questions:

what mode must you be

(a)

(d)

practiced follows the

Module.

when you can answer

(c)

commands you have

to start a

type to start a

new

new file

file?

to

be

named bonzol

command to add (append) text to a file? What is the command to leave Append Mode and Command Mode? What is the command to quit an editing session, What

is

the

Your

return to

save the

First File

31

additions and changes you

made

in that session,

and return

to

the Shell? (f)

What

is

the

command

to display a

list

of the filenames in your

account? (g)

What

is

the

command

to

have a copy of

a file printed

on the

line printer?

Answers: (g) Ipr

Note:

(a) Shell

(b) vi

bonzo

(c) a

(d)

[E^

(e)

ZZ

(f) Is

filename

If

you correctly answered question

(d)

you are awarded the

Houdini lESCAPEI Artist Award. Please turn to the last page of Module for your extravagant certificate, suitable for framing.

32

Your First File

this

Command Summary Visual Text Editing

Command a

ESC

zz

Commands

Function



Moves you

into

2idd text to a

file.

Append Mode, where you can

Append Mode and Command Mode. Escapes from

Quits working on the

returns to vi

writes changes

file,

made

in

an editing session, and returns you to the Shell.

Shell

vi

filename

Starts

a

flename Is

^

Ipr

filename

existing

file

named

for visual editing.

list

of

names

file

in

your account

(Is

list.

Has a copy of filename (Ipr

who

or retrieves an

file

Displays a



Commands



line

Presents a

printed on the line i^vinter

inter).

list

of

who

is

currently logged onto

your UNIX system. date

look

abc

Displays today’s date and time.

Looks

in

dictionary

for

correctly

spelled

words

beginning with abc.

passwd

Changes account.

passwo/d assigned to your UNIX (Remember your new password!) the

Your

First File

33

book.

the

of end

the

at

located

is

map

this

of

copy

B second

Map

A

35

oudini

i\

,



is given

^0

tkw

day

of

— in the year. for distinguish e'd

and

miraculous escapes executed from the Append tAode

Module Four

M

Editing Files Using the Visual Editor

O D U L E 4

Introduction

We

seldom express ourselves precisely in work. As a result good writing involves adding to our

first

attempts.

An

first

drafts of written

revising,

editing,

and

advantage of text processing with

and ease with which changes and additions can be made. words and paraLetters,

UNIX

is

graphs

precision

the

can

be

easily

or expanded, moved around. A copy of

replaced,

the

paper

(with

all

revi-

sions) can then be printed,

having to retype the entire manuscript.

without

Although there are dozens of UNIX commands availediting

text,

able

for

an

introductory

essential

this time.

set

and very

commands

will

More

only

of

versatile

be used

at

specialized

procedures will be included in later Modules.

One approach

to the editing process

37

Prerequisites To employ this Module you should be commands introduced in Module Three:

Command

able to use the following

Function

vi [filename

or

Starts

retrieves

moves you from Allows you

a

to

file

for

the Shell to

start

(Moves you from ESC

a

vi

visual

to

and

Command Mode.

appending text

Command

editing

to

the

file.

Append Mode.)

you no longer want to add text to a file. (Moves you from Append to Command > Mode.) Signals that

ZZ

Saves changes quits

made during an

work on the

file,

editing

session,

and returns you

to

the

Shell.

Objectives After completing this

Module you should be

able to:

(1)

Access an existing

(2)

Position the cursor on desired lines and words within a

(3)

Delete

(4)

Replace

(5)

Undo the effect of the last text change command entered; and Add more text wherever you want in the body of a file.

(6)

letters,

file

for editing;

words or

letters or

file;

lines;

change words;

Procedure This Module contains five sections. Files and filenames are considered in section one. Section two introduces several cursor moving

commands, while

The Visual Editor

text

changing

commands

are discussed

in

tion four.

The

you

section asks

fifth

appear

in sec-

your text editing several points throughout the

Self-check quizzes appear at

skills.

commands

Additional text appending

section three.

to practice

Module.

Log onto your UNIX account following the procedure you learned After the Shell prompt is displayed, proceed to in Module Two. the

section.

first

Files

From

(1)

the Shell

and Filenames

Mode, type

the

command

®

Is

which causes the Shell your account. (The

to display the

®

sary to

let

the Shell

The screen

will

including the

The

Shell

means

know you

press the

files

prompt

the

command.)

your account, {first and second). then displayed, indicating that the system is

names of the files you began in Module Three is

files

are finished typing a

display the

awaiting your next Shell

(2)

you have in RETURN key and is neces-

names of

in

command.

Recalling an Existing File for Editing: In Module Three you used The the command vi filename to begin creating a new file. filename you assign to the file (for instance, first or second) becomes the identification label used to let UNIX know which file you want to work with. Once the filename is assigned, you must

use the same filename to recall the

file

for further editing.

which you began in Module Three. To call the file up for visual editing you must type the following command sequence (two words):

We

suggest you edit the

file first

vi

first I

The beginning all

of the

tioned

at

file,

lines of the

space

appear on the screen (perhaps length). The cursor will be posi-

file will

depending on

the start of the

®

its

first line.

The Visual Editor

39

Yes, the

command

mand used

to reenter a file

is

exactly the

same

as the

com-

to start the file in the first place:

vi

filename

®

where you supply the filename.

Once you will

type vi filename and press the

®

key one of two things

happen:

(a)

the filename you type after the vi is the name of an already existing file, the Shell recalls that file for you to edit; or

(b)

the filename you type is not the name of an existing process of starting a new file with that name begins.

If

If

What happens

you want

if

incorrectly type the

to

name? The

work on an

existing

file,

file,

the

but

Shell will search for a

file with the filename exactly as you typed it. Because the name of the file is typed incorrectly, the Shell won’t be able to find a file with that name. Therefore, it will start a new file with the misspelled Jylename as its name. To stop the process of setting up a

and return (3 )



Locate

to the Shell, type the (upper case)

Map C

at

new ZZ command.

file

the end of this Module, and find the box

marked; Shell

Lo cate

the arrow leading downward from the Shell with the label vi filename\ (where filename is the name of the file you want to edit: in this instance it is the file named first). According to Map C, if you are in the Shell Mode and enter the

®

command

filename you are

The command mand Mode.

moved

into

vi

what Mode?

filename moves you from the Shell to vi ComIt is only from vi Command Mode that you can begin editing a file. Make sure you find that transition on Map C.

When

editing a

ular words,

vl

file

remove

a particular point.

you often need

to correct the spelling

of partic-

specific lines of text, or insert additional text at

With the screen full of lines of type, how can you tell vi which specific word or line you want to change or where you want to add more text?

40

The Visual Editor

The

cursor, or

moving

light rectangle, is central to

com-

municating with the visual editor and must be moved the word or line you want to alter.

Cursor Moving The Arrow Keys: The (1)

basic

Commands moving the cursor through These are separate keys on some

method

for

by using the arrow keys. and the h, and terminals

a

file is

Rmm R

to

k,

j,

and

1

keys on others.

Once you have called up a file for editing with the y\ filename command, the cursor should be at the first line of the file. If this line does not contain text, press the down arrow key until the cursor is on a line of text.

R

and Locate the key with the arrow pointing to the right press it. If you did not see the cursor move when you pressed it, press the arrow key again while carefully watching the cursor on the screen.

The cursor should move

the cursor does not

one character. few seconds. UNIX

to the right

move immediately

wait a

If is

time sharing system, which means that it shares its brain among you and the other users. UNIX may not be able to follow your every command as soon as you issue it. (If the cursor still does a

not move, depress the key marked ESC and then try again.) I

Try each of the four arrow

(2)

to

move

keys.

I

What happens when you

the cursor too far to the left?

Beyond the

try

text to the

right?

move the cursor up, down, right and left through the text. NOTE: If the four arrow keys don’t move the cursor, you may have made a mistake during the logging in process when you told UNIX what type of terminal you were using. If the You should be

cursor

is

not

Twenty-Eight:

able to

behaving

properly,

see

Trouble Shooting entitled

the

section

Specifying

of

Module

Your Terminal

Type.

(3)

the middle of the second line of text and, using the arrow keys, move the cursor to the beginning of that Select a

word

in

word.

The Visual Editor

41

W)

(5)



Press the right arrow |—»| key four should move four spaces to the right.

more

times.

The cursor

Augmenting the Arrow Keys: You can include the number keys (1 - 9) as part of arrow commands. The result is to move the cursor several lines or characters at once.

— — Now

For instance, try pressing the 4 key and then pressing the down arrow\^ key. Did the cursor move down four lines?

key.

press the

number

3 key followed by the

Again, the cursor should

move down

down arrow

[J]

3 lines.

Warning: Many terminals have an extra row of keys located directly above the number keys. These keys may be labeled FI, F2, F3, etc. These are called Function Keys and do not have the same action as the convenUonal number keys. Instead, they will cause much

grief

if

unintentionally struck.

Avoid them

for

now.

Try the 2 key followed by the up arrow, then 4 |—»| 3 Q] and Rather than repeatedly pressing keys tension releasing) to include

you want

to

Note

when you

that

move

it

is

usually easier (but not as

numbers preceding arrow keys when

the cursor several spaces or lines at once.

press the arrow keys the editor does what you request (moves the cursor) and then waits for your next command. You can issue cursor-moving command after cursormoving command without leaving the Command Mode. Find the

arrow key commands headed?

in

Map

C.

Are they

single

or

double-

These double-headed arrows represent the actions of two-way commands. These commands do not move you into another Mode, and do not require that you use the RETURN or

[e^

take effect immediately originating Mode.

You have probably

keys.

They

upon being typed, and you remain

in the

noticed that there are limits to where you can rnove the cursor on the screen. If you try to move the cursor past the left margin or to the right beyond the last character of your text. It does not move but instead you hear a beep. You cannot go

42

The Visual Editor

beyond the text which you have added. (Remember that blank spaces, whether between words or accidentally placed at the end of a line, are characters.)

(7)

Select another

word near the bottom of the

keys followed by arrow keys to place the cursor the word.

(8)

text. at

Use number

the beginning of

The Search Command: An easier way to move the cursor to a specific word in the text is with the search command. When you type (from Command Mode) ! specific the cursor will move to the word specific in the text. word somewhere near the top of the your screen of Move the cursor to the word you selected by typing

Select a

(9) text.

/ [wor3\

where word

is

As you enter

(10) text).

the word that you want the cursor to find. the slash and the target word the terminal displays

what you type

moved

in the

After you

specified

lower

left

Append Mode (and

to

®

word

press

in the text.

this display

®

the If

corner of the screen.

it

key,

is

the

You

are not

not entered into your

moves

cursor

does not, press |ESC| and

to

the

try again.

ESCAPE? The slash-search command is a vi Command Mode process and |ESC| makes sure you are in the Command— and not Append — Mode.)

(Why

press

another word and use the slash-search command to move the cursor to that word. The slash-search command is a powerful way to locate a word in your text. It is a two-way command— you are always returned to Command Mode. Select

(11) Finding Clones: If the word

you

select in this exercise

is

found

more than once in your file, the search command can go to only one of them at a time. Pressing the n key (for next) will send the cursor to the next identical word in your file. Repeat this process and the next instance of the and you will locate the next .

word.

When

.

.

.

.

the editor has reached the end of a

back to the beginning of the

file

.

file

it

will

loop

and continue the search.

The Visual Editor

43

No

(12)

doubt you used the word

the

more than once

in

your

file.

Type

®

/the

and move to the next the by pressing the n key. The n is a two-way command.

Two-Way (1)

Text Changing

command

Commands

Deleting Lines: Lines of text are easily deleted. To delete an entire line of text, position the cursor on any character on that line

and

type:

dd Blank lines

(as well as text lines)

can be removed with the dd com-

mand. Note:

You do

not press the

®

key.

As soon

machine does what is requested removed. The dd command is a two-way command.

struck, the line

(2)

is

second d is and ZAP!! The

as the

.

.

.

Undoing an Editor Command: It is possible to undo the effect of the most recent text changing command using another command, the undo

command.

Type the undo, or ‘T goofed” command: u

The

removed

should reappear on your screen. The undo command allows you to go back only one text changing command. You can only issue the undo command from the Command Mode just

line

of the visual editor.

Press u again.

(3)

What happened? Because u undoes

the preced-

command,

ing

pressing the u key a second time will have the interesting effect of undoing the previous undo. This will return

your

file

to the condition

command. 44

The Visual Editor

it

was

in

before you issued the

first

undo

Type

(4)

3(1(1

which

will

cursor

is

delete three lines starting with the line

located.

command.

Bring the lines back with the undo

(5)

Time

to Fill in the

What

(b)

Where must

(c)

What

is

is

(a)

the

the

Blanks! Consider the following questions:

command

(a)

Answers:

1(6)

on which the

to delete

one

line of text?

the cursor be positioned to delete a line of text?

command

dd

(b)

Deleting a Single Word:

to delete eight lines of text?

anywhere on the

It is

line

possible to

(c)

remove

5dd

single

words from

the text.

Move

the cursor to the

first letter

of any word and type:

dw The dw command stands

Nice disappearing

for delete word.

act,

isn’t it?

Now i(7)

bring the

Place the cursor in the middle of a

mand. Does

(8)

word back with the u command.

it

delete the whole

word and

try the

dw com-

word?

Position the cursor on the

first

letter

of another word and

press these keys:

3dw As with most

vi

used preceding the

Command Mode commands, numbers dw command

can be

to increase the effect of the

com-

mand.

The Visual Editor

45

(9)

Deleting Specific Characters: Select a letter someplace in the text and move the cursor to that letter. Delete it with the command (lower case): X

The X command It

(10)

is

deletes only the single character under the cursor.

the delete one character at a time

place an x over a character,

command.

and instead of leaving

(Now you can a

smudge, the

character disappears.)

What do you expect 6x

will

The space between words on

do? Try

a line

is

it.

a character just as are letters

or numbers.

Thus, the x can be used to delete unwanted spaces between words.

(11)

Another Quick Review: (a)

What

(b)

What command

(c)

What command

(12) (d)

is

the

command deletes

to delete

an entire

line of

your

file?

one word?

deletes the one character under the cursor?

Without referring to the commands, return to your current file and remove one more line, one more word and one specific letter.

Answers:

(a)

dd

(b)

dw

(c)

x

Replacing a Single Character: The

commands

dd, dw,

and x allow you to selectively delete lines, words and characters. At times what is needed is the substitution of one character for another. The r command replaces the one character located under the cursor with the very next character that you type. For instance, imagine the cursor is located at the w in the word two. If the r command were typed, followed by the letter o, then the w in the word two will be replaced by an o. The word two becomes too. This

46

may seem

vi

confusing, but the action we’re describing

The Visual Editor

is

not.

the

Move the command

cursor to a particular letter and replace

by typing

it

r

followed by the replacement character. with several other characters in your file.

That

Now

(13)

command

dogcatcher^s back.-ther&''s

Breaking

Up

a

a character

is

to

long what

is

really

making

it

Id

Like to

replace

Long Line: One of the handy uses of the replace break one long line into two lines. If a line is too

command dle,

Practice the r

two

needed

is

for a

RETURN

to be placed in the

mid-

lines, right?

Select a long line in your text.

Move

between two words near the middle of the

the cursor to the space line.

Type the

replace r

The Visual Editor

47

command and

then

press

®

the

You

key.

'‘space” character between the two words with a

move

the second part of the line should

works because the

®

is

to a

replacing

are

new

®

As

.

the

a result,

This action

line.

just another character to the visual editor.

One- Way Text Changing Commands (14) Substituting for a Single Character:

The

command

r

replace a single character with one other character.

allows you to

Often an author

programmer needs to substitute several characters for a single character. The s command will substitute for the one character under the cursor whatever you type until you press the lESCI key. or

Select a

word

in

your

you might like to word and type (lower

that

file

cursor over a letter in that

Type one or more characters, then press |ESC| mand, the s command must be followed by

.

Position the

alter.

case):

comwhen you are

Unlike the |ESC|

r

finished entering text.

The

difference between the r and s

command removes replace the

single

is

important.

single

new

Each

The r will The r com-

character in your text.

one character with a

mand makes to the

a

commands

character.

the single substitution and returns you automatically

Command Mode

You

two-way command).

(r is a

are not

Append; you do not use the |ESC| key. In contrast, the s command allows you to substitute as many characters as you wish for the one removed character. The s command moves you from Command Mode to Append Mode and leaves you there until you use the lESCj to return to Command Mode (s is a one-way command). left

in

(15) Substituting for a

Word:

exchange a specific word in your text for other words. Position the cursor on the first letter of a word. Type the command: It

is

also possible to

cw

The cw stands at

48

for change

the end of the

The Visual Editor

word

word being

.

A

dollar sign ($) will

replaced.

You then

now

appear

can type the

replacement text. Although the command removed only one word, you can replace that one word with several words, entire sentences, or pages.

Typing the cw

command removes

the one

word and moves you into the Append Mode; therefore everything you type will be entered as text until you press the ESC key (16)

Weird Characters on the Screen: A common mistake is to try to move the cursor, thinking you are in Command Mode, when you are actually in the Append Mode. A series of weird characters or "[A"[B"[D"[D) will appear on the screen (not unlike a Monty Python movie). If this happens, you are in the Append Mode, and those "K or "[A type characters are the control characters associated with the arrow keys. The visual editor is following your instructions and happily adding control characters to your file. Should this happen you need to press |ESC1 and use the x

command i(17)

to delete the control characters.

and cw commands allow you to subtext for a single character and for specific words, respecYou can also substitute for entire lines in your file.

Substituting for Lines: The stitute tively.

s

on any character in a line that is a likely candisubstitution and enter the command (lower case):

Place the cursor

date for

cc

Whatever you now type will be entered into the file in place of the one line that went poof! You are not limited to entering only one line, but can append any number of lines at this point. (18)

Append Mode/Command Mode: It is important that the function of the various commands be understood. Look again at Map C. Whenever you leave the Shell and enter the visual editor you are All this means is that the always placed in Command Mode. machine is programmed to understand and act on a limited number of specific commands. These result in moving the cursor, deleting or changing text, or moving into Append Mode. an append command is given (such as a to 2Lppend text or cw to change a word) the machine is programmed to move you out of

When

and into Append Mode. Once in Append Mode, every character you type will be put in the file as text and

Command Mode virtually

The Visual Editor

49

displayed on the screen.

ESCAPE

You remain

Append Mode

in

until

you

This means you must tell the editor you are finished adding text and want to return to the Com-

press the

when mand Mode,

|ESC| key.

regardless

of which

particular

command you may

Append Mode. The ESCAPE key Command Mode!

have used back to

When

to enter the

is

the

way

doubt about what mode you are in, press the ESC key. If you are in Append Mode (adding text) you will be moved to the Command Mode. If you are already in Command Mode, pressing the |ESC| key will do no harm. It will inform you that you are already in Command Mode by harmlessly “beeping.” in

I

Appending Text (1)

to

a File

Module Three you used the a command to append text when you initially started a file. The a can be used any time you want to In

add text

to the right of the cursor.

Pick a place in the text where you could add more text and move the cursor to the last letter of the word just before where you

make the addition. Then press the a key. You are moved to Append Mode and whatever you type will be entered as text. Add several words and then press ESC to return to Command want

to

Mode.

The

command

allows you to start adding text to the right of the cursor. But what if you need to add text to the left of the cursor (as the first character on a line, for example)?

(2)

a

Inserting Text: Select a place to add some text (such as the beginning of a line). Move the cursor to that place and use the 1

command to insert (i — insert) text. The moves you from Command Mode to Append Mode. Every character you type after typing the command will be entered as text in your file starting with i

i

the space to the

50

left

The Visual Editor

of the cursor.

(3)

Add

several words or lines

The way

of text.

to

indicate

you want to stop adding and return to vi Com-

that text

mand Mode ingly, with the

Figure

1

not

is, I

i

surpris-

a

I

Figure

ESC key

1

I

indicates

where the various Text Appending Commands

adding text relative to the position of the cursor: a appends text to the right of the cursor, and i inserts to the left.

start

(4)

and i keys. Position the cursor on your file, press either key, add a word

Practice using both the the a

the

first letter

of a word in

of text, and note where the

Opening

a Line Below:

already existing lines.

on

that line

It

new word is

is

placed.

add text between two

also possible to

Select a line,

move

the cursor to

some

place

and type (lower case): 0

The

(5)

0 stands for open a

new

line

below the cursor

line.

A

space

opens up for a new line between the line where the cursor is located and the next line in your file. [When you enter the o command on dumb terminals the line below a ppear s to be removed. Panic not — it will reappear when you press ESC and the screen is

The next line is not deleted, just temporarily make room for the new one (or ones).]

‘‘redrawn.”

over”

to

‘‘covered

can continue typing as long as you wish; you are not limited to t hat one line. As with all Append Commands, you must use |ESC| to let the machine know when you are finished adding text and want to return to Command Mode.

Add some new

Opening

text.

You

a Line Above: In addition,

above the line

in

which the cursor

any character on {\\q mand (Upper Case):

first line

is

of text

you can open up located. in

your

Move

file

a

new

line

the cursor to

and type the com-

O The

O

stands for Open a line above the cursor

line.

A new

above the cursor should open up and whatever you type

The Visual Editor

will

line

be

51

added at that point. Again, if the first line “disappears” it has not been removed. The O (Upper Case O) command is the easiest way to add text to the top of a file. As you have now discovered, it can be used to open a line for text above the first line.

As with

command, you can continue

the o (lower case o)

typing as

long as you wish; you are not limited to that one line. Because these two open a new line commands move you from Command to Append Mode, you must use the |esc| key to signal when you are ready to stop adding text and return to Command Mode. (6)

Summary

of

append

on

Append Commands: You now know how to the

text

cursor.

four sides of This ability is all

summarized

in

Figure

the

as

your

cursor

point,

i

inserts

2:

with

i

a

left;

appends to the right; O Opens the line above; and o opens the line below.

To make sure you

You

key.

Figure 2

are in

v/

as

it

can save the

Shell by typing the

a

I

starting

the

to

q

file

Command Mode now

is

press the [esc

written and return to the

command:

ZZ (8)

Time

to Fill in the

from Shell

to

Command

and

vi

Command Mode

finally

lowing questions on (a)

What

is

Blanks: Look

the

Map C and

at

to

Append Mode, then back

back to the Shell.

Map

follow the path

Locate answers to the

to

fol-

C.

command

to

move from

the Shell to

vi

Com-

mand Mode? (b)

What to

52

are four

the

commands

Mode where

to

text

(c)

what mode must you be arrows?

(d)

After entering an o or

In

The Visual Editor

O

move from can

to

be

vi

Command Mode

added?

employ the cursor moving

command, what Mode

are

you in?

What

(e)

command

the

is

appending text and want

(f)

What command

(g)

your

What What

(h)

the

is

command

Command Mode?

starting

new

a

file?

UNIX of com-

to leave the Shell, terminate the

Mode, where

a

new

set

understood?

is

What command do you use

(i)

begin

to

session, and return to Reality

mands

vi

saves the

command

the

is

to return to

are finished

new (and improved) version of memory of UNIX and returns you to the Shell?

the

file in

know you

to let the editor

to

add text

text

after

to the line

below the

cursor line?

How

(j)

Answers: editor

(d)

would

(a)

you

filename

vi

(b) a,

Append Mode

(h) logout

(i)

and enter the a

0

add

(e)

i,

o,

[ESC

(lower case)

(j)

O

(c) (f)

Command Mode

ZZ

(g) vi

place cursor

on the

word?

of the visual

filename last letter

of the word

command

Another Practice

(1)

particular

a

File

Mode. If you logged out, log back Once the Shell prompt appears you into your UNIX account. should start a new file which we will call experience. From the Shell

You should

still

be

in

the Shell

type:

In this

new

file

we’d

ing text processing

is

like

vi

experience

you

to describe

going.

® how

the process of learn-

Summarize what you have learned so

whether or not you are enjoying the process, and what suggestions you’d make about improving these Instructional Modules. Keep the lines short, don’t correct mistakes as you are entering the text, and just type away. Attempt to enter as much text as quickly

far,

as

you can.

The Visual Editor

53

Enter at

(2)

least

practiced in later

(3)

30 short

lines.

Forty lines

Modules more useful

make

will

the activities

to you,

Now

go back and make corrections to this text using the commands that were introduced earlier (the slash-search I word command, arrow keys change word cw command, etc.). A summary of the commands you have used is included as the final pages of this Module. Be sure to try each of them several times as you write your new experience file.

E

Examine what you have

(4) line;

open up

a line

above

that line

(5)

Find several places

(6)

Change one word

(7)

Delete one line and add

(8)

Remove

to

Move

the cursor to the

Return

add more text and do

so.

into another word.

the

to the Shell

Make a paper Shell command

new

text in

and save the

its

place.

(a)

file

using the

copy of the

(line printed)

of “Filling

mands append cursor’s

ZZ command. experience using

Blanks”:

— — "

What com-

cursor.

that

®

experience

Consider the rectangle in the diagram at right to be the

file

make

sequence: Ipr

Round Four

first

and enter an introduction.

the period at the end of a sentence and sentence longer with the s command.

(9)

(11)

written.

text to the

left, right,

above,

and below? (b)

You have now words and

54

practiced the

lines.

The Visual Editor

commands

You have

also

that delete characters,

used the

commands

that

substitute or change characters, words and lines.

mand

that substitutes text for

in the

appropriate box in the following chart.

five

one character

s

is

and

Fill in

The comis

printed

the other

commands.

Character

Substitute

Word

Line

s

Delete

Answers:

(a)

O I

i

a

0

(12)

Your

experience

Character

Word

Line

Substitute

s

cw

cc

Delete

X

dw

dd

file

Modules; add as much (13) Please

Module

read

be useful as you

will

to

it

the following

as

complete the next

you can.

command summary

before beginning

Five.

The Visual Editor

55

Command Summary Shell

Commands

Command vi

Function

filename

Starts

or

retrieves

a

named

file

filename for

\\sual editing.

Displays a

Is

Ipr

Has

filename

a

1/s/

of

file

names

your account.

in

copy of the specified filename printed on

the Vine printer.

who

Presents a

list

who

of

is

currently logged into

your UNIX system. date

look

Provides today’s date and time.

Looks

abc

in

and displays words beginning

dictionary

correctly

spelled

a

of

list

with

the

letters abc.

passwd

Changes the passwo/d assigned account.

Cursor Moving

#

(h,j,k,I keys)

Commands

Moves

cursor one line left.

arrows

Moves

#

/ word

Moves cursor forward through

Moves mand.)

56

Commands

or one space right and

n

The Visual Editor

cursor

to

your UNIX

(Don’t forget your new password!)

Vi Text Editing

BmmB-

to

number

next word.

up/down

of lines or characters. text to word.

(Used with /word com-

Text Changing

Commands

Two-Way Commands (Automatic Return

to

Command Mode)

Command dd

#Jdd

dw

# dw

Function

Deletes cursor line of text. Deletes

number #

of lines of text.

Deletes one word from text.

Deletes

number # of words from

text.

Deletes the one character under the cursor.

#

X

r[3

u

Deletes

number # of

characters

from

text.

Replaces the one character under the cursor with the next character typed c.

Undo: Reverses

change action.

last text

Append Mode Commands One- Way Commands (Leave

a

You

in

Append Mode)

Appends (adds)

text to a

file

to the right of cur-

sor.

i

0

Inserts (adds) text to a

file

to the left of cursor.

(lower case o) Opens a line below cursor line for

appending

text.

The Visual Editor

57

o cw

(Upper Case O) Opens a for appending text.

Change word: exchanges new in text that

cc

Change text that

S

line

it

text for

one word

exchanges new text for one removes.

line in

new

line in

line: it

it

line

removes.

Substitution: exchanges text that

above cursor

removes (same

text for

as cc

one

command).

Mode Changing Commands Command ESC

Function

Escapes from text Append v/

zz

Mode and

Command Mode.

Quits work on a ing

that

editing

file,

writes changes

session

into

the

The Visual Editor

made

dur-

memory

UNIX, and returns to the Shell Mode.

58

returns to

of

book.

the

of end

the

at O)

iosaJ O)

"^(g) ino3oi

oo

•O

o

~a

ZZ

B

located

1

® djnpdoojj IIlSOT

C/D

o

u

luwUaflJ' lA

L

AV3

0;

33



key

>

ed version of your


!

entered:

to re-encrypt

it

newname

instructs the Shell to overwrite the old encryptfile

with the

new encrypted

new nonencrypted version you may want to remove it.)

still

The Pack and Compact Commands: At many is

is

filename

and then wish

filename

forget that the

account

line

command:

crypt

The




symbol? will

have numbers

edit a particular file?

command

What

stop the Shell from overwriting an

Command Mode command

when you

(c)

will

when you use

file

displayed

you

command

Shell

existing

log into

remove the include

(until

editing

numbers

numbers? for any files that

you logoff)?

How

could you have numbers appear in every you logon to your account?

What command produces

a listing of

all

files

file

every time

your

in

Home

directory, including the dot files? (g)

How

could you have the word format interpreted by the Shell to mean nroff -ms [whatever file you enter] as an argument to format, and have the output sent to the page command?

Answers! (d)

setenv

the .login

(a) set

noclobber

EXINIT

file,

(f) Is

set

-a

number' (g)

.login file.

288

(b) set

Account Management

enter

number

(e)

(c) set

add setenv

nonumber

EXINIT

format 'nroff -ms \l*

set \

number'

to

page' into the

&

M O D U

Module Seventeen

L E

Backgrounding a Process

17

Introduction At various places in this book we have mentioned the concept of running a job in the background. Backgrounding a process refers to having a current Shell process (nroff, Ipr, etc.) run in such a way that the terminal

is

free to accept other Shell

commands. You

are

then able to work on one task while UNIX quietly completes a different Shell command sequence. This Module presents an introduction to the

commands

that affect

background processes.

Prerequisites Before starting this Module you should have completed the exercises through Module Ten. In particular, make sure you are familiar with the & backgrounding character introduced in Module Six.

Objectives After completing this (1)

Execute

a Shell

Module you should be

command sequence

work on some other UNIX

able to:

while you simultaneously

task;

289

(2)

Monitor jobs or processes that are running and

(3)

Terminate jobs or processes that are running ground.

in the

background;

in

the back-

Procedure The procedure steps for this Module are presented in three sections. The first section deals with running jobs in the background. The second section discusses how processes currently running in the background can be stopped and re-started (a feature available

on BSD

4.0,

4.1,

and

introduces the batch

UNIX versions

4.2

command— a

only).

The

final section

cheaper way to run a job

in the

background.

Running a Shell Command Sequence (1)

Log onto your UNIX account.

Select

one of your

for the exercises in this Procedure Section. lines

(2)

would be

Background

in the

A

file

larger text files

with 300 to 400

ideal.

The Ampersand: The &

character was introduced in

This creature allows you to background a Shell

To further explore how mand sequence: nroff

-ms

this

command

command works

[filename] |

Ipr

Module

Six.

line.

enter the

com-

&

Appending an ampersand to any Shell command line places the process into the background (where it is quietly but efficiently executed), and returns control of the terminal to you. (Kind of reminds us of the old tv series Outer Limits.)

You

can then attend to other

UNIX

activities,

without

having to wait sequence. Most

first

complete your requested command versions of UNIX will inform you when the process is complete by writing a brief message on your screen. At some locations you may need to periodically check whether the process has been comfor

to

pleted.

290

Backgrounding a Process

(3)

Waiting for Godot: The simplest way the background job is completed is

check on whether or not to use the wait command. to

Enter the Shell command:

®

wait

the job sent into the background has not been completed, this command will cause UNIX to pause until the backgrounded job is complete. Using the wait command returns UNIX to the state it If

would have been

in

if

you had not sent the job

into the back-

ground.

you get bored waiting for the process to finish or want to continue with another UNIX task press the DELETE key. This will If

delete the wait process, allowing the job to slip quietly back into the background.

(4)

Performing a Process Status Check: While UNIX is attending to a Shell Command sequence such as the one you entered in Step

Two, type the following

Shell

command:

®

ps

You should

receive a message which appears similar to the follow-

ing:

TT

12581

ia

STAT R

12438

id

R

PID

The ps command stands time to report

all

the formatter

TIME

COMMAND

:02

ps

:46

nroff -ms experience

and can be used processes submitted from your account. for i^rocess status

at

any

speedy (or if you sent a short file) the process status may not show that you are backgrounding an nroff process (as the process may have already finished). If this happens, submit a longer file to be formatted using the & to put the process in the background, then retype the ps command. If

is

particularly

Backgrounding a Process

291

your backgrounded process. PID means Vrocess Identification’, this is the “job number assigned by UNIX to the command listed under the heading Com-

Note the PID number assigned

to

mand. The other headings are not of interest

(5)

Killing

at this time.

Backgrounded Process: You can terminate

a

grounded process with the

kill

command. For example,

a

back-

to kill the

process identified as 12438 in the above sample process status check, you would enter the sequence kill 12438. Shell

Enter the following Shell

command sequence

where

[pYd]

is

abandon Note:

(6)

if

number found

the process

when you entered (kill)

the job

is

command

the ps

the

®

PID

kill

already completed,

background job

UNIX will with that number.

in the prior step.

associated

process

Shell

for your

it

cannot be

killed.

Quiz Number One: (a)

background the process the file named samneric and

What command would cause UNIX of locating misspelled words in put these words in a

(b)

named

What command can be used tiated in question (a)

(c)

file

How Shell

above

is

to

spellsam?

to see

if

the spell process

ini-

completed?

UNIX you’ve changed your mind about the process initiated in question (a) above and don’t wish to

could you

tell

have the process completed? Answers:

(a) spell

samneric

>

&

spellsam

(b) ps

(c) kill

PID

Stopping and Re-Starting Jobs (Available Only on

(1)

Versions)

Stopping a Foreground Process: Some UNIX systems will allow you to temporarily stop whatever process you are working on. In effect the process is placed in a state of suspended animation, while you are

292

Some

moved back

into the Shell

Backgrounding a Process

Mode

(microprocessor cryogenics).

one of your first

and

several lines of the

the

at

same time

practice files for visual editing. file

are displayed,

press the

Z

key once):

®

CTRL-Z

You should should now

Once the type (hold down CTRL

receive a note indicating Stopped and a Shell prompt appear. If those two events do not take place, your

system probably does not have these features, and you should proceed to the next section: Running Jobs through Batch.

you have stopped the job and are presented with a Shell prompt you can perform any Shell activity you desire— your stopped process will silently await your return. Perform some modest Shell command action (perhaps look up the spelling of all words beginning with the letters uni). Leave your file in suspended animation for another moment— you’ll soon learn how to re-call it. If

(3)

Checking the Background report

tems the

all

that

ps

The ps command will processes running on your UNIX account. Most UNIX syssupport the CTRL-Z command also offer an alternative to

command

for

for Processes:

checking

on

stopped

or

backgrounded

processes.

From

the Shell enter:

jobs

A

®

of backgrounded or stopped processes will be displayed for your edification. The jobs command is the quickest way to discover these processes (much quicker but less thorough than the ps list

command). (4)

Pulling a Stopped or Backgrounded Process into the Foreground: Any Shell command sequence which has been backgrounded or stopped can be brought back into the foreground.

The process you stopped

command)

is

still

in

command). following command: the jobs

few moments ago (with the CTRL-Z suspended animation (you just checked with It can be brought into the ioreg^round mXh the a

fg

® Backgrounding a Process

293

Voila!

editing process reappears,

Your backgrounded

continue work. with the

Write the

and you may

onto the disk and return to the Shell

file

ZZ command.

Warning: The following sequence of events (a)

Begin editing a

(b)

Make some changes

is

dangerous:

file;

to

it;

Stop work on the file with the CTRL-Z command, and perform some Shell task (such as look up the spelling of a word);

(c)

was placed in limbo, again enter the vi filename command and thus call up a new buffer copy of the file [as it was before you began this editing Forgetting that the buffer copy of the

(d)

file

session in step (a)]; then Start editing this

(e)

second version of the

file.

At this point, in addition to the disk copy, you would have two temporary copies of your file, one in the background and one in the foreground. Both copies are now different from the original disk copy and different from each other. If you write one file onto the disk, and then write the other, the second will overwrite the first, resulting in the loss of the editing performed on the first copy. Be certain to go back to files that are stopped rather than

up new versions of the file.

call

The backgrounding of you need

to look

editing processes

up the spelling of

some other file to write out a Just remember to bring file. rather than starting over with a

(5)

Killing a

word

especially useful

or

if

when

you want go

into

portion for inclusion in the present the

file

back into the foreground

new

edit

command.

Backgrounded Process with chkps: As you now know,

one of the uses of

number

a

is

a process status

assigned to your

check

command

is

to discover the process

so that you can

kill

that pro-

On most UNIX systems that support the CTRL-Z, fg, and jobs commands these two actions can be accomplished in one easy step. cess.

From

the Shell enter the

command

chkps

294

Backgrounding a Process

-iv

line:

®

This

command

individually

will

list

processes currently in the

all

background. You will be asked whether you would like to terminate any of the processes. If you want the job killed, enter yes (or y) and press the key. If you want the process to continue, simply press This Shell command sequence is a useful addition to your .logout file, as it will detect any unwanted processes which might continue to use computer time after you logoff. For

®

®

reason,

this

.

the chkps

command

is

noted

in

Module

Sixteen:

Account Management.

(6)

Review: (a)

you are editing a file named rhett and need to know how to spell the word butlet\ how could you find the word using the spell command, without ending your editing session?

(b)

Once you had

If

editing the

What

(c)

(d)

the correct spelling,

how would you

return to

file rhettl

command

Shell

could you use to see suspended animation?

stopped and

in

What

command

Shell

identifies

all

if

the

file

rhett

is

backgrounded Jobs and

permits you to decide whether each should be continued?

Answers: (d)

chkps

(a) First type

CTRL-Z, then look

but

(b) fg

(c)

jobs or ps

-iv

Running Jobs Through Batch While UNIX

designed primarily as an interactive operating system it is possible to run Jobs through the UNIX batch facility. Each batch Job is held by the system until UNIX has the resources necesis

one time. This contrasts with interacJobs, which are worked on in a piecemeal fashion. Although

sary to complete the Job at tive

batch

processing

is

usually slower then interactive processing,

it

does offer the advantage of allowing you to specify certain limits to the Job that cannot be done with interactive Jobs (e.g., run at night when costs go down or exit Job if it takes longer then a specified

Backgrounding a Process

295

amount of cpu

batch

In addition,

time).

is

often considerably

cheaper (and easier on the system) then running jobs interactively or in the background. Batch jobs can be run with a wide variety of options. We will present only the basic process. Additional information is available from the on-line UNIX Programmers* Manual.

Running Running

a Batch Job: a batch job

The a

is

batch facility

is

accessed from the Shell.

command same command lines

two step process:

(1) the Shell

you want followed (these are the you would submit from the Shell if you were running the job line(s) that

are entered into a

interactively)

commands is then commands are executed. Shell

file;

the

(2)

file

containing the

sent to the batch processor, where the

For instance, assume you have a text file named report2 that you want to format. The steps necessary to batch this nroff job would be:

(a)

First create a “script” file containing the Shell

be submitted to batch (in this instance, the would be nroff -ms report! Ipr); and to

command command

line line

\

(b)

Then submit ate Shell

the script

command

This general process

(1)

is

file

line (e.g.,

Just place the

the Shell into a

Use the

script

scriptfile).

file

in

this

command (s) you would

example

is

easily

normally use from

file.

visual editor to create a

contain only the following Shell nroff

batch

by entering the appropri-

described in the following steps.

Creating a Script File: The created.

to batch

-ms filename

new

file

Command

called script

which

will

line:

>

filename is the name of a file in your account that you would like formatted. The filename nfile is the name you would like given to the formatted version of this file. In this

command sequence

(Programmers can replace this line with the Shell command quence necessary to compile a program.)

296

Backgrounding a Process

se-

(2)

Submitting the Job: The following Shell command sequence will ask UNIX to process your batch job (i.e., have the command (s) you entered into your script file obeyed): batch

The

file

named

script

is

®

script

sent to be batch processed.

In response,

batch will do two things:

you the jobname being assigned scrip 17429, and

(a)

Tell

(b)

Create two

files in

file

(3)

will

use

it

is

the

line(s)

file

more

to-be-worked-on.

batch involves at least two

command(s) which

consists only of the Shell

the Shell to perform one or

mand

you

next Procedure Step.

one

file(s)

such as

batch. out.

as scripl 7429) as

The process of having jobs run through files:

this job,

your account: batch. err and

Note the assigned jobname (such in the

to

specific processes,

The

and the to-be-worked-on

file

instruct

and the other

containing Shell com-

file(s) are

not the same

file.

A

General Nroff Script File: It can be awkward having to go into the script file and change the name of the to-be-formatted file every time you want to batch (or botch) a formatting job. Much more useful is a script file that permits you to specify the to-beformatted file as you give the batch command.

To

create such a general script

line in

your

nroff

script file

-ms

$1

file

you should replace the present

with the following

>

line:

$2

>

With the nroff -ms

$1

the following Shell

command sequence

$2 line in your script

file,

to batch

you could use

process the

file

oldfile:

batch

The file oldfile named newfile.

will

script oldfile newfile

®

be formatted and the output placed

Backgrounding a Process

in

a file

297

and $2 are symbols interpreted by the Shell to mean: replace these characters with the first and second arguments that

The

$1

follow the

name

Consider sequence

another

of the script

named

in a file

with

example:

the

the Shell

script,

command line. above Shell command command sequence

batch Shell

in the

file

®

script experience n.exper

batch

named

and place this material into a file named n.exper. (Note: Arguments are discussed in Module Sixteen: Account Management.)

will

(4)

have batch format the

file

experience

you forget the batch job name otherwise check on the status of

Checking the Batch Que:

In case

assigned to your job or wish to your batch job you may enter the following Shell

command:

®

batq

inform you of the status of your batch job (along with any others being processed) whenever you enter the batq Shell

UNIX

will

command. (5)

Removing and then

a Batch Job: Occasionally you

realize that the job

processing.

Jobs

sent,

was not

but

not

(removed from the batch que).

may send

a job to batch

ready for the requested processed, can be cancelled really

you need is the jobname scripl7429) and the following

All

assigned to the batch job (such as

command. To remove command:

the job scripl7429, you would enter the following Shell

batrm In general, to

remove

-j

scripl7429

a batch job

®

you use the following

command

sequence

batrm where jobname

298

is

the

name

Backgrounding a Process

-j

[jobname

®

that batch assigned to

your job.

(6)

Additional

Commands: Two

additional Shell

commands should be

noted: (a)

batman, which summons forth an overweight and poorly conditioned middle-aged man who dresses funny and drives a very unusual car which closely resembles a 1963 Cadillac, and

(b)

robin, which will do

all

that

batman

will

do, but with

much

less self-confidence.

(7)

A

Final Review:

(a)

What

Shell

script file

and sent (b)

What

command sequence would you

named

script

to

have

files

place within the

formatted by nroff -ms

to the line printer?

command

would you use

have the

file

formatted and printed using the batch script script created in question (a)?

file

Shell

line

to

experience

named

Answers:

(a) nroff

-ms

$1

Ipr I

(b)

batch

script experience

Backgrounding a Process

299

Command Summary

Background

(Most Versions With Berkeley Enhancements)

Command &

Function

command sequence in the You are given a Shell prompt.

ground. wait ps

Pause

ps -g

until

Perform '.that

back-

Shell

Place

backgrounded job

is

complete

a process status check.

List processes

belong to you (your terminal).

Perform

process

a

status

check.

List

all

processes that belong to your account.

king] kill -9

g

batch

batq

batrm

Kill

jobs

number #.

process

Nuke named

process

Execute a Shell

number #.

script as a batch job.

Check the batch que.

Remove

(BSD CTRL-Z

named

4. 0,

a job

4. 1, 4.

Stop a process. List

all

from the batch que.

2 Only)

Immediately place into

Shell.

jobs currently stopped or running in the

background. fg

Bring a backgrounded or stopped job into the

foreground.

chkps

-iv

Perform

a

for a process

BSD

prompt command (not available on

process status check. kill

4.2).

MEDICAL CENTER 4150 CLCMENI

Vfc

300

Will

Backgrounding a Process

, .j

;

• coos

Module Eighteen Parts

and Wholes Mr

Introduction

When

we

writing a long or complicated paper,

usually focus

on the

development of only one part at a time. For instance, we may complete the problem statement or summary, and leave the remainder of the text alone. It is a waste of computer resources to have the entire paper formatted and printed whenever we want to examine only the part under construction. Conveniently, UNIX allows edited)

us to both separate parts as well

Additionally,

is

it

several separate

as join

files files

into

make commands

together to

possible to have Shell

files as if

(and

smaller

they were a single

more

easily

larger

files.

function on

file.

Prerequisites This Module

will

be most useful

if

you:

(1)

Have completed Modules One through Ten;

(2)

numbers displayed next to each a file (see the section on setenv EXINIT A ccount Management)

Have

line

when you edit Module Sixteen:

line in

(3)

Have the Shell command Module Sixteen); and

(4)

Have reviewed the process of working with directories cussed in Module Fifteen: The UNIX Directory Structure.

set noclobber in

your

.login file (see

as dis-

301

Objectives Upon completion Create

(1)

files

Add

be able

to:

editing;

from another

text

will

which contain blocks of text drawn from the

you are currently

file

(2)

new

Module you

of this

file

to the

file

you are currently

edit-

ing; (3)

Create a

(4)

Use

file

containing the contents of several

several special Shell characters to perform various Shell

functions

(e.g.

format and print text or compile and execute

programs on several (5)

Use several new or

files;

files

files

with one

command

line);

and

nrojf options to format selected parts of a

file

that are sections of a larger paper.

Procedure The procedural steps in this Module are presented in four sections. The first section reviews a method of breaking a file into separate parts while working in an editor Command Mode. The second section reviews several methods of joining files together from within an editor Command Mode. A new Shell procedure that accomplishes a similar task in a different way is also introduced. The

how you

can use filename expansion characters to perform Shell functions on several files simultaneously. The final section presents nroff Shell command options which can be used in the production of a paper or text. third section illustrates

Separating a File into Component Parts

(1)

Writing Out Text: To write out a block of text from your current file to a new file you need two pieces of information: (1) the line numbers of the first and last lines of the text you want to write out, and (2) a new filename for this material.

As an example suppose you and wish

302

Parts

to

save the

and Wholes

first

are visually editing the

seven

lines

of text

file

letter,

mom

(perhaps as an

introduction to your next bi-annual letter) as a separate titled

mom. start). From

vi

Command Mode

:7,

you would

(to

be

type:

®

w mom. start

7

file

The

lines specified by the line address (7,7) would be copied and written into a new file. The text would then exist in two places— in

you are currently you did not want this text the

file

to delete

(2)

editing, in

your

and

new

in a

mom

letter.

file,

mom. start. If you would need

file

it.

Various forms of the write

command

are

Command

summarized below:

Function

:J,6

w

newfile

Creates newfile copying text lines

:I,6

w

»

Appends copy of

:1,6

w! oldfile

oldfile

lines

Overwrites (replaces) lines

1

1

to 6 to

oldfile

1

to 6

end of

oldfile

with contents of

to 6

Note: These are visual editor commands. To use these from the ex line editor you would drop the colon (:).

commands

Joining Files Together from within an Editor

Two methods exist for editor Command Mode. (1)

(2)

joining

files

»

Writing out Text: The :1,6 w mand reviewed above can be used append it to another.

together while working in an

form of the write comtake part of one file and

oldfile

to

Reading in Text: To read another file into the one you are editing, you need two pieces of information: (1) the name of the file containing the material you wish to copy into your current file, and (2) the location (line number) in your current file after which you want this

new

material to appear.

Parts

and Wholes

303

Suppose you are visual editing a file named letter. mom and wish to send her a copy of the poem you created for your English CompoThis

sition course.

Command Mode

poem

is

contained in the poem

(while editing the

letter.

mom

file.

From

v/

you would type

file)

the following: :8 read

A

copy of the

following line

file

8.

®

poem

poem would be read into letter, mom immediately Once you read in this material it becomes a part

and may be treated like the rest of the text. copy was made of the originating file, and it is left unchanged. of your current

file

Joining Files Together (3)

From

A

the Shell

Copying Two Files to Create a Third: In an earlier Module you met the Shell cat command as one way of viewing files (the fly-by, catch-me-if-you-can approach). Additionally, cat allows you to merge the contents of two or more files. Cat (which stands for concatenate, a word which few people recognize and even fewer can pronounce) is an excellent tool for the task of combining files.

To have

the

poem, letter

file

file

poem combined with

enter the Shell cat

The sequence

poem

to use this

cat

sequence:

mom >

poem, letter

command I

file letter.

command

letter,

[filel

the

[file2\

in general

>

mom

into a

new

is:

[file3\

®

and file2 are the files to be combined, the > is the “larger than” right arrowhead (the redirect symbol), and fileS is

where

filel

name

the

selected for a

new

file

to receive the contents of files

1

Note: The contents of each file is not affected. The original filel and file2 will still exist, while a new filed has been created to hold a copy of both filel and file2.

and

(4)

2.

Beware!!!

Do

not use the

name

of an existing

file

to receive files

concatenated with a single arrow head (as demonstrated in the two examples in Step 3). At best you will be prohibited from executing the command, and at worst the existing file will be lost. If

304

Parts

and Wholes

your

does not contain the Shell following will occur: The cat command’s the

.login

file

following the

one

to cat

file

file

>

of

contents

its

(if

command

action

first it

has any).

into another using a single arrow

the loss of one of the

In this

files.

mand sequence would be

noclobber the is

empty

to

Thus, trying

head

will result in

manner, the following cat com-

disastrous:

cat paperl paper2

>

®

paperl

would first empty the file paperl then copy the empty paperl, leaving you without the first part of

In this instance cat

paper2 into

your paper.

The

cat sequence can be used to concatenate any

number of

files.

Thus, the sequence

>

cat filel file2 filed file4 filed

an enormous

will create

of file

1

®

megafile

{megafile) with copies of the contents

file

to filed.

Combining Two

Files:

It

is

also possible to cat

one

file

onto the end of another, without affecting the second.

command

The

Shell

line

poem

cat

will

directly

append

a

copy of the poem

The double arrowhead tents of the

first

file

» to

is

»

letter,

file at

the end of the

interpreted to

whatever

is

®

mom

in

file letter.

mom.

mean, “add the con-

the second, without

first

deleting the second.”

Due

to the ease with

good idea

which you can combine

down

files,

it

is

often a

and more easily managed files. These smaller files can be edited and revised separately. Whenever you want them re-assembled you can put to break a large file

them back together with the

cat

into smaller

command.

Before proceeding to the following review, log onto your account

and (a)

try the following:

Select

two

files

and cat them together into

Parts

a

new

third

and Wholes

file.

305

(b)

Visually edit the

you

file

command.

tions a divorce, using the :w (c)

From

the Shell add one

»

cat filel

(8)

file

to

command

another with the

line

file2.

Review Number One: Consider the following questions: (a)

What

command would you

v/

your current

file in

a

new

enter to place lines

named

file

1

to 33 of

debby.suel

(b)

What vi command will replace the contents of an existing named schubert with lines 29-200 of your current file?

(c)

What

(d)

What

will

append

onto the end of the

file

vi

magoo (e)

command

vi

current

command

will

read

in

tortie

holding the contents of

(a) :1,33

w

read magoo

debby.sue

(e) cat

File

The following

file

sarah peter

Name

lines are

r/c/c?

the content of the

file

named

file

named

file?

files

(b) :29,200

file

36 through 74 of your

named

command sequence would

Shell

(d) :40

lines

40 of your current

at line

What

Answers:

(1)

and give the two por-

just married

create a

named

w! schubert

new

sarah and

(c)

:36,74

peter^l

y/»rick

> tortie

Expansion Characters

an example

listing

of the filenames in one

of our directories:

modi mod2 mod3 mod4

This group of file

name

mods mod6 mod? mods

Parts

modindex

nmodl nmod2

names

smodl smod2 tmod4 tmod4

tmod4 vi-summary

be used to demonstrate the role of expansion characters in performing various Shell funcfile

tions.

306

mod9

and Wholes

will

9

All these files contain text relating to the Modules.

For instance, modi contains Module One, mod2 contains Module Two, modind contains an index to the Modules, smodl contains a list of words misspelled in Module One, vi-summary is the table of vi commands, and tmod4 contains a section of Module Four written out for testing a complex formatting command sequence. (Not to worry— you won’t be quizzed on this material!)

Bracketed Filenames: Sequential numbers or letters placed within brackets have a special meaning to the Shell. For instance, the Shell will understand the notation mod[l-9] to mean ‘‘act on all files from modi through mod9y You can also bracket individual (non-sequential) filenames. For example, mod[13569] will be interpreted to mean “act on modi, modS, mod5, mod6, and mod9y

Note

that the characters enclosed in brackets are not separated by a

space or

comma, nor

rootname

is

there a space between the brackets and the

(here, mod).

Suppose we wanted to list the files in this directory an entire Module. The Shell command

the

will list

names of

the

®

mod\l-9\

Is

files

that contained

containing entire Modules:

modi mod2 modS mod4 mod5 mod6 mod? modS mod Create four short (for

instance, call

files

them

should be very short. the

using the

same

root in their filenames

rootljoot2, rootS, and root4).

After

all

Each

are created, use the brackets to

file list

files:

Is

where

root

is

ruod#-#l

®

the root you used for your filenames, and

#-#

are

the alphabetical or numerical sequential labels.

Using

file

big deal

it

name expansion itself.

It

is

a

characters with the

good way

to test

what

Parts

Is

command

files will

is

no

be accessed

and Wholes

307

these characters to perform a more dramatic Shell action, however. This is demonstrated in the following step.

when you use

(5)

Format and Line Print

Files:

You

can use a filename expansion

For examformat and print Modules One through

character to sequentially format and print several

should we chose to

ple,

Four we would enter

this Shell

nroff

-ms mod[l-4]

sequence: Ipr

|

®

modi through mod4 would then be formatted and printed

Files

Page numbering

together.

(6)

Command

files.

will

be continuous.

Matching Any Set of Characters Is

would

yield this

list

of

file

(*):

mod*

The command

®

names:

modi modi modS mod4 modS mod6 mod? mod8 mod9 modindex matches any one or more characters. Thus the Shell command Is w* would list all filenames (regardless of length) beginning with the letter m. The Shell command Is *m would list all filenames (regardless of length) ending with the letter m.

The

(7)

*

Matching a Single Character: The command ? modi

will

generate this

list

of

file

®

names:

smodl nmodl

The

?

matches any

single character.

As another example,

the Shell

command Is

308

would

list all

letters

mod.

Parts

modi

®

filenames of four characters length beginning with the

and Wholes

Your

commands introduced you will name the component

effectiveness with the

can be increased

if

in this

Module

of a large

files

project filename 1 filename! filename! filename4 filename! where filename is the same root name (the above examples have used the

word mod). This root name obviously should have specific meaning to you. It could, for example, be the topic of your paper or series of programs.

(8)

Review Number Two: Consider the following questions:

What

(a)

Shell

command sequence

will

format the

files

named

format the

files

named

manic 1, manic!, manic!, and manic4‘l

What

(b)

Shell

command sequence

will

apaper, bpaper, dpaper, and tpaper? (c)

What files will be formatted with mand sequence: nroff city[l-!]

(d)

What

filenames could be listed with the

(e)

What

filenames could be listed with the following

Is

any

all

Is

com-

command?

tree*

command:

Ihead*

Answers: (d)

the following Shell

(a)

nroff manic\l-4]

(b)

nroff \abdt]paper

filenames beginning with the word

character

followed

by

the

word

tree

(e)

head

and

all

(c)

city I

city2 city3

filenames beginning with

finishing

with

any

other

character (s).

Summary

Character

Table of Filename Expansion Characters

Function

*

matches any string of characters

9

matches any single character

[]

matches any characters enclosed

[-]

matches any sequential range of characters

Parts

in

brackets

and Wholes

309

Nrojf Options Several options are available to structure

how

nrojf prepares the

copy of your paper. Options can be used to specify that only part of your paper is to be formatted. For instance, only page 9 would be printed using the following nroff command: final

nrofF -o9

The option (minus

filename

Ipr \

sign, lower case o, 9)

must immediately follow

the nroff command separated by a space.

If

you want

a file to

be given page numbers starting with page ten,

you (-nlO). This is very convenient if the file is actually the second section of a paper and the first nine page section has already been formatted.

another option

is

Each option formats and

inserted into the nroff Shell

is

available to

Command

line

which

The presence of an option is indicated to UNIX by the inclusion of a single minus sign (-) followed immediately by the name of the option. You can use more than prints

your paper.

one option (for instance both the option to limit output to specified pages and the option to halt after every so many pages). However, all options must appear between nroff and the filename, and there must be a space before each minus (-) sign in the command line.

The general

Shell

command

line for indicating a nroff

-option

A

filename

nr

option

is:

®

Table of Selected Nroff Options follows as the last page of this Module. Additional options exist and can be learned through accessing the on-line UNIX Programmer's Manual with the man nroff

command.

310

Parts

and Wholes

Selected Nroff Options

Option -

0#

Function (minus lowercase o) Limits output

#

pages indicated by the pages 3 through 5

.You

5

For example,

provided.

only would be indicated as -o3-

could ask for

the notation

to only those

-o-6

.

all

You

pages up to page 6 with

could ask for

after page 4 with the notation -o4-

case 0

,

4,

all

pages

{minus, lower

minus).

-n#

Numbers

-s#

Halts output every

#

For example, the option -nl4 would cause the first page of your paper to sport page number 14, with the second page as 15. the

first

on

a

#

pages.

.

The option

-si

is

you are producing your finished typewriter-like printer and wish to

useful in nroff

paper

page of text

if

hand feed individual sheets of high quality paper. Output resumes when you press SPACEBAR. Usually -s without an argument is set to be one page.

Parts

and Wholes

311

Module Nineteen Phototypesetting with Troff

Introduction

&

Troff -ms

*

The UNIX troff text processing system interprets formatting commands in files to produce typeset quality output, such as the text of this book. The content of this Module is intended as an introduction to typesetting. For a more detailed examination of the topic consult the Nroffl Troff User's Manual and A Troff Tutorial, available from

Bell Laboratories or

your favorite computer science book-

store.

Prerequisites

You

will

(1)

Have mastered

be able to use

this

Module once you:

the use of formatting instructions (Modules

Five and Nine);

312

(2)

Are acquainted with advanced Shell commands (Module and

(3)

Have

access to a phototypesetter on your

UNIX system.

Six);

3

Objectives Upon completion (1)

Use

troff or

of this Module you should be able troff

basic type size

and

to:

-ms formatting instructions to specify the style desired

when

document;

typesetting a

(2)

Determine type size and style for section headings and words or characters within a document;

(3)

Utilize special troff characters.

specific coo

Mr

Procedure The procedure first

tion

Module contains four

parts.

The

section provides an overview of the troff text formatter.

Sec-

two

describes

section of this

introduces

how

line length.

specific

troff

The

requests.

third

section

keeps track of such variables as point size and The final section considers how to use troff with the troff

-ms macros.

The troff

the

is

troff Text Formatter

a text formatter just as

commands embedded

is

nroff.

The

troff

system interprets

format text for a phototypesetter in the same way that nroff is used to format text for a line printer or terminal. When preparing a document for phototypesetting you employ the same basic formatting instructions that you have already used with nroff to specify paragraphs, spaces, indents, and centered text. In addition to the nroff formatting options you have already used to produce typewriter-like print, the phototypesetter has the ability to vary the size of type {point size), and style of type (fonts: Bold, Roman, and Italic) used in the printing of the formatted text. If

you include

in

a

file

to

troff instructions in a file, that file

nroff to be formatted for a line printer.

In

can

still

be sent to

most cases the

line

accommodate your type changing requests, so nroff simply ignores them. The troff system parallels the nroff system — printer cannot

both are text formatters,

troff

is

not a preprocessor to nroff (as are

and neqn). You do not send a other— you select one or the other. tbl

file

first

to

one and then the

Phototypesetting

3

1

Determining Type Characteristics This

how to determine commands without the

point size and

section will illustrate

first

font of output using troff

use of the -ms

macro package.

(1)

Point Size: The size of the typeface used in printing a document is measured in points. Most of the text in this book is set in 1 1 point type. A point is 1/72 of an inch: thus, six point type is 1/12 inch high, while thirty-six point type is V2 inch high.

Point Sizes Available on

The

point sizes usually available on trojf are:

6 point type: Six point type

7 point type:

is

of

little

Seven point type

8 point type: Eight points

is

is

use, except in advertisements for eye doctors.

not

much

people.

When

for

12345!#$%&

11

point type:

in the

When

.12345!#$%&

12345!#$%&

often used as book type, but

is

hard to read for

course of

in the

human

course of

events,

human

it

becomes necessary

events,

When

in the

human

events course

it

16 point type: The necessary course 12345!#$%&

point

type:

necessary course.

course. 1

4

Human

human events

human events

are

a

12345!#$%&

A

humane, necessary 12345!#$%&

20 point type:

3

became

12345!#$%&

14 point type: The course was a necessary event. 12345!#$%&

18

becomes

it

12345!#$%&

12 point type:

necessary

is

12345#$%&

12345!#$%&

10 point type:

necessary

of an improvement

a dull basketball quarter.

9 point type: Nine point type

many

troff

Phototypesetting

5

22

point

name 24

is

type:

Necessity,

thy

course.

point

human

type:

Are

coarse necessary?

events

12345!#$%& 28 point type: Hopefully not.

12345!#$%&

36 point type: We hope. 12345!#$%& (2)

Unspecified Point Size: The default point size setting for most troff systems is: 9 point type, which

is

the point size of this line; or

10 point type, which was specified for this

line.

Unless you specify a different value, the formatted text

will

be

in

the default point size.

(3)

Specifying Point Size:

To

specify a different point size for

some

portion of text, you must include a troff instruction as the line in

your file immediately preceding the line or lines of text you want formatted in a new point size. For example, if the following lines are included in a file, the .ps 14 will be read as a point size request and the lines which follow will be set in 14 point type.

Phototypesetting

3

1

.ps7^ This is the beginning of text set

at

14 point type.

All text will be printed in 14 point type until a

new

instruction for

some

different point size

is

included.

.ps77

This

the

is

The formatted

of type in the eleven point

first line

size.

typeset output will be:

the beginning of text set at 14 point type. All text will be printed in 14 point type until a

This

is

new

instruction for some different point size is included. This is the first line of type in the eleven point size.

To change

point size you place the

line preceding the text

you want

command

set in

|

.ps

number] as the

number\ point size type.

The change begins with the next line of the file. Whole lines are set in specified type sizes when you use the .ps number\ command.

When

using

Once you you

troff,

commands

point size

specify the point size,

instruct

otherwise.

all

commands.

text will be set in that size until

you

(If

are one-way

find

that

your

point

specifications are mysteriously cancelled at the start of each

paragraph you are probably using the -ms macros. read the -ms macros section of this Module.)

Changing Point Size Within

a Line:

You do

size

new

Be certain

to

not have to limit

yourself to specifying the text point size for entire lines of your

Should you need to make a change within a specific line (or even within a word) you place a \s number] in front of the character in the line where the change is to occur. file.

|

For example, consider: this

When

formatted, this appears this

3

1

6

dis\sl6play of te\sllxt

Phototypesetting

display

as:

of

text.

7

In the previous paragraph

we

played around with the point size in

the words: “within a line or even a word.” The following text line— with embedded commands— was used to format that line: .

.

within a line (or

.

e\s\^ve\s\\n

w/\s11As14/7/\s11/7\s11 a w\^\4o\s\(ird\^\\) you place

(5)

....

Spacing: In music, the notes which are played are essential — but so is the silence between the notes. In setting the type for a printed page, the white space between lines of type is as important as the size of the type used. This book is set with a vertical spacing of 13 point, because the text is 11 point. The vertical spacing of troff output can be changed. For instance, by includVertical

ing the instruction: .vs 9 in the text the amount of space between lines is reduced. The net effect is to put the type close together and make it difficult to read. Usually the vertical spacing is set to be two points larger than the size of the type selected for the text.

To change

the vertical spacing include the .vs

command:

number

Font Selection for Text The phototypesetter usually offers 3 or 4 separate text fonts, such as Times Roman (the standard or default typeface). Times Boldwhich includes Greek letters, mathematical symbols and other gems. As is the case with point size changes, font changes can occur either between lines or within a line (or word). face,

(6)

Times

Italics:

Italic,

plus

a

The rroj^command

special

to

character

change

font

fo/7t to Italics is:

.ft I

When

the

.ft

I

command

is

placed alone on a line in the text,

all

which follow are set in I/^7//c5. The .ft command is a one-way command. It remains in force until a new font specification is lines

entered. Phototypesetting

3

1

8

For instance: It is

when

easy to change fonts

typesetting.

.ft I

This text

be set in Italics. text will be in Italics

will

In fact

all

until a

new

.ft

font

is

selected.

R

After another font specification is

entered,

the text

When

the

file is

be set

font

(7)

set in the

is

new

font.

formatted the resulting output

easy to change fonts

It is

is

command

selected.

typesetting.

In fact all text will be

in Italics.

is

when

is:

This text will

in Italics until

After another font specification

entered, the text

is

set in the

new

a new

command

font.

Boldface: Likewise, to set type in Boldface employ the nroff one-

way command

B

.ft

(8)

Roman: To change

the type used to

following example demonstrates

B Here

the

command

is:

R

.ft

The

Roman,

all

three fonts:

.ft

.ft

feel bold,

I

here .ft

I

Italic,

R

here Roman.

The following formatted sentence Here

3

1

I

feel bold, here Italic,

Phototypesetting

reflects these various

here

Roman.

moods:

9

(9)

Changing Fonts within a Line: To change fonts in the middle of a word or sentence, enter one of the following commands ahead of the characters you want set in a particular type: \fl for Italic,

\fB for Bold, and

\fR for Roman. Place the change font instruction immediately preceding whatever

character

is

to

be set

in the

For instance, the following

new

font.

line in a file

\fBdis\fIease\fR

produces the formatted: disease. To interpret the example, the \fB instructs the formatter to shift to Bold type. It then sets d i s in Bold type. The \fl changes the font to Italics, thus the letters are set in Italics. The last \fR merely resets the font to Roman for whatever follows.

ease

Another example: \fBantidis\fIestablish\fRmentar\fBian\fIism\fR appears

as:

SLntidisestablishmQniansinism

Note:

When

remain

using troff without the -ms macros a font change

in effect until

you specify

a

new

will

font.

does not interpret the nroff command .ul to mean underline the next line of text. Rather, it will Text may be underlined with troff, italicize the next line of text. but it is a somewhat complicated task. Additionally, boxes can be

(10) Underlining

and Boxes:

troff

drawn around words or blocks of text using troff commands. It is also a difficult task. If you have the -ms macros available to you it is much easier to use the boxing and underlining capabilities of If you would like to learn how to draw lines tliat macro package. boxes using Nroffl Troff User 5 Manual.

or

format

troff

commands

alone,

refer

Phototypesetting

to

the

3

1

Determining Page Characteristics (1)

One-Way

troff Requests:

trojf keeps

track

of the specific line

and several other one-way commands which determine the formatting of your text. Every time it starts length,

point

size,

font,

formatting a line of text, troff checks point size, font, line length, etc.

its

memory

for the specified

troff begins with a

“default”

Roman

font etc.)

value for each of the variables (10 point type, which it will use until you specify otherwise.

Troff Requests and Default Values Input

Command

Default

What

it

Governs

.ps

#

10 point

Point size

.ss

#

12/36em

Size of space

character

.ft

F

Roman

Type font used

.pi

#

11 inches

Page length

.po

#

0 inches

Page offset printed

.vs

#

12 point

Vertical spacing

6.5 inches

Line length

.11#

Note on Table of Troff Requests and Default Values: The # symbol is never used in the commands. You substitute an appropriate value or

in

Em’s

inches (3.5i), points (38p), centimeters (11c), picas (22P), (3m) for the #. The F is the appropriate Font: B,R, or I.

When you

are using troff without the -ms macros, the values

any of these variables

you

remain in force until you specify new values. They are ordinary one-way commands.

set for

320

Phototypesetting

will

1

When you 12,

.11

enter a font, point size or line length instruction, (.ps 7.5/, or .ft B) troff stores the information in its memory.

Then, when

checks for the latest instruction as it begins formatting the next line in your file, it finds the new specifications for font, point size or line length. It will then use the new instructions as it formats the line.

(2)

Special

troff

typesetters

is

One

Characters:

their ability to

is

of the

more

useful

of

aspects

print characters not available

on

a

A

sample of some interesting characters available with presented in the following Table of Special Font Characters.

typewriter. troff

troff

Special Font Characters

Input

Character

Input

Character

\(sc

§

\(+-

±

\(cu

U

\(ib

c

\(aa 1

\(ga \(*a

a

\(if

oo

\(*b \(*g

/3

\(is

I

y

\(pt

oc

\(*D \C*H

A

\(es

0

0

\(br 1

\(*s

I

\(rh

wr

\(*W

n

\(lh

“IW

\(ci

o

\(->

\«-

\(ct i

\(ua \(da \(dg

.

\(bu \(14 \(12

• '/4

V2

Note on Table of Special Font Characters: Each of the characters listed can be used by including the input code as a “word'’ in the text where you want the character placed. The point size of these creatures has been changed to 12 to better highlight their appearance.

Phototypesetting

32

For example, the following It is

line in a file:

as easy as \ (*a

produces the following formatted It is

A more the

(3)

complete

list

Nroff! Troff User

5

as easy as

line

f3

y

.

of text:

.

of the special font characters

is

contained

in

Manual.

Obtaining Output: Because the troff system is a text formatter just like the nrojf system, you send a file to the troff formatter (for phototypesetting)

instead of the

You

quality output).

will

file

there

is

a

queuing system

File

Length

command

similar to

filename

at

your location you might use;

-Q

troff

typewriter

(for

to the phototypesetter:

troff

If

nroff formatter

normally use a Shell

the following to send your

(4)

a

\ (*b \ (*g

[filename

Most phototypesetting machines have the files which can be printed. A max-

for Typesetting:

maximum page length imum length of 35 feet a

to

(about 35 pages) is not unusual. Before longer than several, pages, be sure to inquire

sending a file that is about the page length maximum in effect at your location. You may wish to discuss submitting longer jobs or breaking a long file into smaller parts with the typeset operator.

(Note: typeset operators

are in fact real, flesh-and-blood, genuine people.)

Using troff with the -ms Macros to

Determine Type Characteristics

The most important and

-ms is font are handled. specified remains troff

difference between typesetting with troff alone the way the variables such as point size and type

the case with -ms.

322

Phototypesetting

When you

set the point size using troff,

in effect until

you specify

a

new

one.

the size

This

is

not

(1)

'2)

Paragraph Resets: (3 troff

on

you set the point size with a .ps 16 command command) you would expect all of the text from that point If

be set in 16 point type. This is in fact how troff alone will respond. With troff -ms, however, only the text between the .ps instruction and the next paragraph macro will be in the requested to

(16 point) type size.

As soon

as

an -ms paragraph macro

encountered, the point size the -ms number register associis

be reset to the size stipulated in ated with point size. We have noted in several places how the -ms paragraph macros have a lot of unexpected effects written into them (this topic is considered in some detail in Modules Nine: Advanced Formatting and Twenty: Macro Construction). The font, will

type size, and a host of other page management variables are reset to the values in the appropriate number registers every time you

invoke one of the -ms paragraph macros.

For instance,

where the .psl6 point

included

command

size

is

in

the case

in

the

text will be set in 16 point type, until the next paragraph

file,

the

macro

is

encountered, where the point size is reset to the default 10 point (unless you have specified otherwise). «

Every time an -ms paragraph macro is encountered, the formatter checks the number register named PS to see what point size is specified. Unless you have stipulated otherwise, the .nr PS register it

is

set for 10 point type.

sets the type in

After the formatter checks the register,

10 point.

If

you want

a different default point

you must adjust the number register to another value (such as 12 point). This way every time a paragraph calls for resetting the point size the value you set will be read. size,

To set a document number register to

command

as

you must change the point size read “12 point.” To do so include the following in 12 point type

one of the

first lines in

.nr

With

command

number Whenever the paragraph macros this

the

PS

a

file:

12

register

is

now

set at Voint Size 12.

reset the point size they will reset

to the value of 12 point.

Changing

Default

Values:

The

troff

-ms

formatting

process

begins with deciding upon the basic page and type size characteristics of your paper. You then enter instructions for the appropriate

Phototypesetting

323

and place this material at the beginning of the For example, suppose you want lines to be 5 inches long (for file. 7 inch paper with one inch margins) and a 9 inch page length, set in 11 point type with vertical spacing of 13 point. You would enter

number

registers,

the following

commands .nr

.nr .nr

LL PS VS

the top of your

at

file:

5/

11

13

.pi 9/

Note

that the page length control

is

the nroff instruction .pi and

not an -ms number register. There is no -ms number register associated with page length. Page length is a one-way /zro# command which is not reset by -ms paragraph macros.

Summary

-ms Number Registers Default

Function

Register

324

of

LL

Line length of text

6 inches

PO

Page offset

0 inches

FL

Line length of footnotes

5.5 inches

PI

Paragraph indentation

5

spaces

Ql

Indentation of .QP paragraphs

5

spaces

HM

Header margin

1

inch

FM

Footer margin

1

inch

PD

Vertical offset of paragraphs

Iv in nroff 0.3v in troff

PS

Point size of printout

10

VS

Vertical spacing

12

Phototypesetting

(3 )

Boxes Around Text: The -ms macros provide an easy way to box one or more words of text in your file. To box a single word you use the command .BX word with the word placed next to the command. For example, the following text in your file:

being drawn around the word

.BX

school

(perhaps reflecting the school yard.)

box being drawn around the word

will result in a

\school\

(perhaps

reflecting the school yard).

To box two

more words— or even entire paragraphs— you use the .B1 and .B2 commands. Place the text block within the commands .B1 (to begin the box) and .B2 (to end the box). The -ms macros

will

or

respond with a box of

text.

.B1 These will

lines

of text

in

a file

be boxed.

Note that the box commands precede and follow the to- be -boxed text.

.B2

These

be boxed. Note that the box precede and follow the to-be-boxed text.

(4)

lines of text in a file will

Underlining Text: The -ms macro package

will

commands

allow you to under-

You must individually underline each word, however. The command .UL word\ will underline one word at a time. To underline several words, you need to use the .UL word\ command line

text.

|

|

for each word.

This means that

.UL each .UL word .UL must .UL be .UL individually .UL underlined. Phototypesetting

325

The above display each word must be

illustrates the fact that,

with the -ms macros,

individually underlined.

This completes the introduction to phototypesetting with troff and Additional information is available in the Nroffl Troff troff-ms. User's Manual dind A Troff Tutorial, produced by Bell Labs.

The developer

326

Phototypesetting

for typesetting.

Module Twenty



Macro Construction wr-coog

Introduction In

Module Five you used

nroff requests) to instruct

Module Nine described macro

nrojf formatting

commands

(also called

how to format your text file. -ms macro commands (also referred to

nrojf about

the

which allow you

format your work with greater ease than is possible with nroff requests alone. Module Nineteen introduced the requests used to specify how troff should format more eloquent output for production on the phototypesetter. This Module illustrates how the -ms macros have been constructed from nroff requests. This information will start you on the road to understanding how to build your own macros to meet your indivias

calls)

to

dual needs.

Prerequisites Before starting

this

Module you should be

able to:

(1)

Use nroff requests (Module Five) and the (Module Nine) to have your file formatted; and

(2)

Use

(Module Nineteen)

-ms

macros

perform fancy formatting feats (suggested only for section two of this Module). troff requests

to

327

Objectives After completing this (1)

Module you should be

able to:

Describe the differences between an nroff request and a macro call;

(2)

Access macros and macro packages

(3)

Build basic macros tailored to

(4)

fit

in several different

your

own

ways;

needs; and

Determine the compatibility of nroff requests, the -ms macros and your own home-made macros based on the internal workings of the -ms macro package.

Procedure This procedure section is divided into five parts. The first section presents several simple home-made macros and demonstrates how macros are built by bundling nroff requests. The second section describes how UNIX accesses macros. The workings of a fairly complex macro are illustrated in the third section. The fourth section

examines how nroff

when commands inside a simplified

how

it

fills

are followed.

text

The

lines

and determines exactly

final section

presents a look

segment of the -ms macro package

to illustrate

works.

An

Important Review

an instruction to the nroff formatter about how your file is to be formatted. Macros (like those that make up the -ms macro package) are collections or bundles of nroff requests that can be called into action (hence the term macro call) with a single command (such as .PP). The -ms macro package is a set of macros designed to work together when used to format a file. Recall that an nroff request (such as .ul)

is

The -ms macros were created to make your formatting tasks easier. There may be instances, however, where your needs are not met by these pre-packaged formatting commands. The ability to create

own macros which

then perform complex, repetitious, or boring formatting tasks (and thereby saving you time and energy) can be quite helpful.

your

328

will

Macro Construction

Home-Made Macros (1)

Log onto your UNIX account.

(2)

When

the Shell prompt appears type: vi

This

new

{context)

file

will

®

context

be

the

practice

file

used

in

this

Module’s exercises. (3)

(4)

Enter three paragraphs of text into your new file. Make each paragraph 3 or 4 sentences in length, and write about anything you wish. Begin each new paragraph with the appropriate -ms paragraph macro call (.IP, .LP, .PP, .QP, or .XP).

A

Centered Heading Using nroff Requests: How about placing a centered title above the material in paragraph two? This is accomplished with the following four lines of text.

Place these four lines after paragraph one and before the para-

graph formatting macro for paragraph two: .sp .ce .ul

Paragraph Two

The above four

lines of text will space

the words comprising the centered

down, center, and underline

title.

In this case the centered

be Paragraph Two. If you want some other the line Paragraph Two with whatever text you want. title

will

When

(5)

all

four lines are entered, use the

write the buffer version of the

Enter the Shell

(6)

command nroff

-ms

file

and return

title,

replace

ZZ commands

to

to the Shell.

line

context

\

page

®

formatted version of context displayed on the screen. Paragraph two should appear with a centered title above it.

to

have

a

Macro Construction

329

The four lines necessary to create modest amount of work on your

the centered

title

required only a

you had a file which required 26 centered titles? One option would be to retype (or yank and put) the four lines all 26 times— a somewhat tedious task. This is where a home-made macro can do some of the work part.

But what

if

for you.

(7)

Your

Home-Made Macro:

First

Move with the

and open a new line above At the top of your file, enter the following

to the first line in

O

command.

your

file

6 lines exactly as they appear here:

.de

Ct

.sp

.ne 4.1v .ce .ul

These

six lines are interpreted as follows:

.de Ct

Indicates to nroff that the following lines,

up

to the next

two dots (..), define (.de — define) the macro Ct. The Ct was chosen to remind us of Cen-

line containing only

tered

^

t itle.

down one

.sp

Spaces

.ne 4.1v

Requests nroff to make sure that at least four lines are available on this page: if not go on to the next page;

.ce

Centers the next

.ul

Underlines the next

Concludes

These

line

of text;

line

of text; finally

macro.

from .de Cmo taken together define the macro whenever you have need of a centered title in this file

six lines

Now

Ct.

this

line;

.

.

macro .Ct can be used.

the

The

you would any other -ms macro call. The Ct macro calls for the centering and underlining of the next line in the file. Thus you first enter the macro call, then on the next line enter the text for a centered title.

330

.Ct

is

entered into a

Macro Construction

file

just as

(8)

Return

your context

to

of nrojf requests

entered them

in

At the moment you have

file.

preceding the

Procedure Step

text

.ce,

text for the centered

title.

and

centered

.ul

first

by

(You

two paragraphs and delete

which are located just before the

In place of those nrojf requests enter the a line

titles.

4.)

Position the cursor between the

the nrojf requests .sp,

for

a series

new macro

call

.Ct

on

itself.

Repeat

procedure for each centered title you placed in the file. Your file should now contain the 6 lines defining the Ct macro followed by the three paragraphs originally written. Additionally there should be one or more .Ct macro calls preceding the text for centered titles. For instance, if the centered titles are Paragraph Two and Paragraph Three, your input file should appear

something

this

like the following:

Macro Definitions .LP

Some

text that will be paragraph one.

.Ct (9)

Paragraph Two

.PP

Some

text that will be another paragraph.

.Ct (10)

Paragraph Three

More

When

text.

finished, write this

file

and return

to the Shell (with the

ZZ command). To view

the formatting effects of your nroff

-ms

context

new macro

page

type:

®

As the formatted version of your file is displayed on the screen note how the Ct macro acted on your paper (automatically spaced down, centered, and underlined each centered title). (Note: Some terminals are unable to properly display underlining on the screen. Your printed text can be appropriately underlined, even though on the screen

it

may appear

incorrect.)

Macro Construction

331

(11)

How

Uses Macros to Format: The process of employing macro definition and a subsequent macro call is quite complex: nroff

(a)

The macro

(b)

When

be read by nroff\

with

comprise the macro into the

file at

The

the

Your

macro

the

same

the

make up

nroff

your

requests

file

it

which

location;

the

new macro.

text then reflects the effects of this

Nroff

in

macro and have been interpreted and followed; and

nroff requests (that

macro

In the case of the Ct (a)

first

call

replaces

inserted) are (d)

must

nroff encounters a call for this

internally

(c)

definition

a

this process translates as:

-

read the 6 lines defining the Ct macro (which the top of the file) and store this information

will first

are located at for later use; (b)

When prets

it

macro (c)

Then

macro

nroff encounters a .Ct to

mean

definition

in

call

your

file

it

inter-

“insert the nroff requests located inside the

named Ct

nroff spaces

at this

down one

point;”

vertical line (.sp),

makes

certain

that there are 4.1 vertical spaces available (.ne), centers (.ce)

(d)

and underlines

(.ul) the

The very next

line in

appears as a centered

next input line in your

your

(following the .Ct

file

first

anywhere (12)

that a

macro defined

in that file,

macro

call)

home-made macro. Obvi-

ously macros of this type can be of great assistance.

remember

and voila

title.

You have completed and used your to

file;

at

the start of a

but only within that one

Naming Home-Made Macros: We named

It is

file

important

can be used

file.

macro Ct employing one upper case and one lower case letter. This “mixed case” convention is followed in naming home-made macros to avoid confusion with -ms (all upper case) and nroff (all lower case) formatting commands.

Macro

the

your Ct macro You could re-type the 6 definition lines which in several files? make up the Ct macro at the top of each file (a tedious and somewhat tacky choice) or you could create a permanent macro file and

(13) Creating a

332

File:

Macro Construction

Suppose you needed

to use

place the 6 lines in

with whatever

any

effective in

From

file

This macro

can then be processed along you are formatting, so that your macros will be

file

it.

you

select.

the Shell type:

file

mac

will

be the

name

®

mac

vi

The

file

of your

new

Insert the six lines comprising the Ct

your mac

for macxos.

file

macro

definition into

file:

.de Ct

.sp

.ne 4.1v .ce .ul

When

finished, write this

new

and return

file

to the Shell with the

ZZ command. up your context

Call

macro

file

Before investigating

(14)

for visual editing

definition contained in the

finished, write the

the

file

mac

file, it

and return

how

file.

When

to the Shell.

macros located examine how -ms works.

in

macro package you place calls .PP) in the body of your paper.

to

to

In using the -ms

various -ms macros (such as

What causes

lines of the

to get nroff to use the

would be useful

The -ms Macros:

first six

and remove the Ct

nroff to read the -ms

macro

definitions [analogous to

Step 11(a) above]?

This reading occurs before the process of formatting your paper is begun, and is initiated with the Shell com-

mand after

line

the

(nroff

-ms filename

command

nroff and

Ipr). \

before

By placing the -ms option the

name

of the

to-be-

you cause nroff to read the -ms macro package definitions before it reads your file. The -ms macro package file contains the definitions of each of the -ms macros (for instance PP). This information permits nroff to interpret the -ms macro calls placed within the body of your file. formatted

file



Macro Construction

333

To

ask UNIX to read your

how -ms

similar to

mac

read by the formatter before the

is

command

Enter the Shell

nroff

The

mac

file

file is

read.

line:

mac

-ms

How

do you before formatting contextl In a way

bring our discussion back to the current situation:

context

\

®

page

now

be read after the -ms macro package and before the file context. In the above command line nroff reads the file containing the -ms macros, then it reads the macro definition contained in your mac file. While formatting the file context, nroff file

will

refers to the definition of

when each macro

is

Ct as well as other -ms macro definitions

called for in the trailing context

file.

Did your macro definition and call work? If not, check sure you entered the commands exactly as demonstrated. (15)

to

make

Quote Paragraphs: The -ms quote paragraph call .QP brings the left and right margins in, but leaves the text spacing unchanged. Writers usually prefer to have quoted paragraphs single spaced. The following macro will do just that.

Append .de

the following 11 lines to the end of your

mac

file:

Qs

.sp .Is

.in .11

1

-\-10m

-10m

• •

.de .Is

.in .11

Qe 2

Y assumes

double spacing

is

wanted

—10m -\-10m

• •

These 1 1 lines define two quote paragraph macros and demonstrate how one-way macros are defined. The Qs {Quote start) macro will:

334

(a)

Skip one space (.sp);

(b)

Set the line spacing to single space (.Is 7); and

(c)

move

both the

in ten

ems

(an

left

em

Macro Construction

and right margins (.11 —10m) spacing unit used by nroff and troff).

(.in is

a

-\-10m)

The Qe (Quote end) macro

needed

is

to reset the line spacing to

double spacing and to restore the original left and right margins. You may find use for these two modest macros in simplifying your formatting chores. (16)

Using the Quote Paragraph Macro: Call up your context file for visual editing. With the following two additions, the second paragraph

appear formatted as a quote paragraph:

will

(a)

Replace the -ms paragraph macro used to format the second paragraph with a .Qs (place a .Qs before the first line of text in the second paragraph); and

(b)

Place a .Qe after the

(17) last

of that paragraph

line

— before

the

next paragraph macro.

Now

employ the

Shell

command

-ms

nroflf

mac

line:

page

context

Your text file will be formatted and you can new quote paragraph macro.

®

see the effects of the

Accessing Macros Thus

you have been introduced

far

two methods of accessing

to

macros: (a)

You

can place the macro definitions within the

done

in the earliest exercises in this

the procedure of choice in that are only used in (b)

one

file

was

(as

Module). This method is the case of special purpose macros

text

file;

or

You

can place the macro definitions in a separate file and have that file read during the nroff process (for example, page). This second method is most siminroff mac context |

lar to

A

third

how

the -ms macros are accessed.

method of

accessing

your

own macros

now

will

be

presented. (1)

The Nroff Source Command:

If

you regularly employ

designed macro package, there is an nroff request that save you time and impress your friends.

a

self-

will

both

Macro Construction

335

up your context

Call

as the first line of the

file

for visual editing.

file

mac

.so

where

mac

definitions.

name This command is

the

process— to place the mac (to source in the

mac

Insert the following

of

the

file).

nroff—^wnng the formatting

instructs

file at It

the beginning of your context

in the

file

Now

have your text

mac

include

-ms

context

formatted.

file

in the Shell

by nroff because of the context

this line

command

use the

nroff

to

file

has the identical action as naming the

nroffShtW command line. After inserting write the context file and return to the Shell.

mac

macro

your

containing

file

command

\

®

page

Notice

how you do

not need to

Your mac file will be read source command, located on line 1 of your line.

file.

Rethink — Remember Time: (a)

What nroff command named Xy ?

(b)

What

command

indicates the beginning of a

indicates

the

of

conclusion

new macro macro

a

definition?

Where would

(c)

the definition for a macro be placed to have

available only for use

(d)

anywhere

a set of

rnacros.

What

Shell

named

is

in a file

a file

david.waasl

named mynamed lillian

home-made macros and

What formatting command— located file

file

command would have

file— will have nroff access the

(f)

the

home-made macros

Suppose

formatted using only these

(e)

in

macro

as

the

it

first

nroffl

line

of a

definitions located in the

named my-macrosl

Suppose the

named

.so

kenny-Joyce.

kenny-joyce

file

command is the first line of a What Shell command line will have

my-macros

formatted using only the my-macros and

Macro Construction

file

the

nroff^.

Answers: (d) nroff

(a) .de

X}’

my-macros

(b)

lillian

••

(c) at

beginning of

my-macros

(e) .so

file

david.waas

(f) nroflF

kenny-joyce

The Workings of a Complex Macro Arguments Within Macros: Frankly, it is very easy arguments with macros— but avoid it. They always win. (1)

The following macro in

your

file

for

cally label the

you

will

leave a specified

amount of blank space

to insert a figure or diagram.

space Figure

1

the

first

time the macro

antics are possible because

automati-

will

It

ure 2 the second time, and Figure 3 the third time

Such high powered

to get into

it

is

used, Fig-

is

used,

etc.

macros accept argu-

ments.

Append .nr .de

the following 8 line Figure macro to your

mac

file:

Fg 0 Fg

.ul

.ce

Fg \\n{Fg-Fl Figure \\n{Fg .nr

.sp \\$1

When

finished, use the

this file

and return

ZZ command

to the Shell.

to save the

changes made

to

gem

be

(The workings of

this

will

explained shortly).

(2)

To

leave space for two figures in your text, append these 12 lines

(The commands should be entered exactly as are presented here; the text can be changed to suit your to the

end of your context

file.

interests):

.sp

The following pgure illustrates the of practice time on learning.

effect

.Fg 3.5i Clearly,

the

when a person

commands

they are

actually practices

remembered more

easily than

Macro Construction

337

when

the person attempts to just read the book.

.sp 2

If the preceding figure didn V convince you, this

one certainly

will.

.Fg 2.5i

which concludes

Use the usual

our argument.

(or precludes ?)

ZZ command

to write the

file

and return

to the

Shell.

(3) file,

Because the .so mac command you can enter the command: nrofF

-ms

the

is

context

first line

context

in the

page

\

your figure macros. When you feel comfortable using these macros read on and discover why they work.

Examine the

results of

Behind the Lines in the Macro War: The remainder of this Module explores aspects of nroff and macro construction which are rather technical.

Freak not— it

is

not necessary to master every

how macros work until you begin seriously writing your own macros. For now you should read through it to obtain an overview of how the break, no break, backslash, and title line commands work. You can give this material a second detail in the explanations of

(and third) reading later on.

(4)

Interpreting the .Fg Macro: to the role of

number

You were

registers in the

introduced in Module Nine

formatting process.

The -ms

macros use number registers to control overall formatting tasks such as line length and page offset. Number registers are also used internally, by nroff, to keep track of many things including the As you read the following line-by-line current page number. description of the .Fg macro note how number registers were used.

The process of using macros begins with and then including the definitions either text

file

nroff

or in a separate

file

must read the macro

the

first

internal

338

line.

All definitions of

memory.

Also

Macro Construction

at

definitions before

any

file

line

i

i

the beginning of the

it

by

In either case

reads the text line, starting

macros are transferred

commands

i

creating their definitions

consisting of macros.

In the initial reading, nroff reads the

\

not

inside

the

to

file.

from nroff

macro

i

'

i

definition are

number Later,

performed

in this initial pass

through.

(For instance,

registers can be set to specific values in this first reading.)

when

macros

nroffxs formatting the text, nroff will find calls for the in the text file (for instance .Fg 3.5i). At that point nrojf

locates the definition of the

macro

in

its

memory and

executes

those requests.

Annotation of Requests .nr

Fg 0

A number

appear

Fg Macro

named Fg and is set to This number register request

register

the value zero.

must

in the

is

outside

the

(which begins with the next that the

number

register

before the macro

is

macro

definition .de Fg), so

line:

Fg can be

set to zero

called during formatting.

read (and executed) by nroff only during Because nroff's first pass through the macro.

It

is

this

number

register

command

is

located out-

macro definition, it is not read when the macro is called (with the .Fg command) during the actual formatting of your When Fg is called, only the lines paper. between the .de Fg and the trailing .. are read. side

.de

Fg

of the

This begins the definition of the Fg macro.

.ul

Underline the next

.ce

Center the next

.nr

Fg \\n{FgFl

line of text.

line of text.

Fg translates as “set the number register Fg to whatever value follows the space character in this line.” If this line were .nr Fg 5, the number register would be set to However, what follows the Fg is not a 5. number but directions as to where the formatter can locate the needed number. (We are beginning a short game of Hide and Go Seek.)

The

.nr

The \\n( means

that the value the formatter

needs (to set the Fg number register) is not here either, but is stored in a number register, whose name follows these symbols.

Macro Construction

339

Fg + 1 identifies the number register, (namely itself, Fg) but the +1 stipulates ‘'read the present value in Fg, then add 1 to it.” Thus, whatever value is in Fg will be increased by one unit and then put back in Fg. Thus the numbers ascribed to each figure by the Fg macro will advance by one each time the macro

The

is

Figure \\n(Fg

called.

When

Fg macro call is located in your file, the word Figure and the number held in the Fg register are printed. The \\n(Fg prints the current value of the Fg register (7 the first time the macro is called, 2 the second time, etc.). Because the two prior requests in the macro definition (.ce and .ul) have been read, this line is centered and underlined (Italics in the

first

This line results in Figure

troff).

time the macro

called. Figure

is

1

the

first

2 the second,

etc.

.sp \\$1

This

last line

of the macro definition provides

the space for the figure in the formatted output.

If this line

always be

left

were .sp

Instead, \\$1 space

is

five inches

would

output for the figure.

the

in

5/,

called for.

When

nroff

reads a request followed by a \\$1 it interprets this to mean “insert the first argument to the

macro

call

of space the .Fg

here.”

You determined

when you

macro

call.

.Fg 3.5 for Figure

the

amount

attached the argument to

You

entered the

command

your file [in step (2)] and the resulting Figure 1 had 3.5 inches of 1

in

space in the output.

The

the argument for the .Fg

macro call. That argument is read into the macro because of the \\$1 request on this line. When you put the macro call for the figure macro in your text file [step (2)] you followed the first call with 3.5i and the second call with 2.5i. Each time nroff processes the macro call (whenever it appears in your file) it inserts the number you

Macro Construction

3.5

is

entered following the Fg in place of the \\$1. This gives you 3.5 inches of blank space for the first figure and 2.5 inches of space for the second.

Ends the

(5)

The Mystery

definition of the .Fg macro.

Double Backslashes: The characters that cause nroff to read in the first argument to your .Fg macro are $1. Note that references to both number registers (WnfF^) and arguments (\\$1) within an nroff request begin with two backslashes (\\ ). Why is one needed, let alone two?? of

the

To the nroff command interpreter, the \ The purpose of the nroff escape character

wh at the

I

fol lows as a

ESC key I

command and

nroff comes to a \ it characters as a command, it

the escape character.

is

to tell nroff to accept

not text.

(This

is

the

same

role

plays within the visual editor.)

When

which

is

removes

it

and interprets the following

unless the next character

is

also a \,

then leaves alone.

Commands

which have double backslashes are contained within macro definitions. If only one backslash were used, nroff would remove the backslash, interpret the command that followed and act upon it. As a result, nroff would interpret and try to act on the commands inside macros during its first pass through the macro — although in this first pass nroff is to only read the macro definitions

and store them

for use

when

called.

The second backslash is necessary to “conceal” the rest of request from nroff when the macro definition is first read.

the

For example, without the two backslashes in the line .sp \\$1, nroff would immediately act on the instructions. It would expect an argument to appear, though none would be provided. After all, this is nroff's first exposure to the macro, and is intended only to inform nroff of the existence of the macros and their definitions. You do not want nroff to act on the macro Instructions until after During the first reading it begins formatting the text of your file. of the macro

file

nroff

removes the

first \,

then finding another.

Macro Construction

341

moves on cute

(as

it

backslash the

quietly.

the

result

when

nroff returns to the

of a macro

call)

there will

This time through the backslash

left.

command

Later

is

Summary: The

macro

to exe-

be only one

is

removed, and

to

“conceal” the

exposed and followed.

role of the

second backslash

is

of the request from nroff when the macro definition is first read. This first backslash is “peeled off” at the time the macro is rest

initially

read so that the rest of the request can be interpreted and

acted on

when

the macro

is

actually

used.

This leaves a single

command when

backslash to identify this as a

the

macro

call

is

processed during the formatting of your paper.

(6)

A

Note of Caution: The macros introduced in this Module were carefully designed to work with the -ms macro package. Be aware that not all home-made macros will be compatible with the -ms macro package. The source of most problems is the way -ms uses internal number registers. The -ms paragraph macros reset various number register values in a multitude of strange ways. Unless you understand and anticipate their actions, your macros may not work as you expect. For example, the .RS macro trols

the

number

left

indent level.

call

resets a

number

All -ms paragraph

i

i

register that con-

macros check

this

determine the current indent level. This is why you can include one or more paragraphs between the .RS and the .RE and each paragraph will appear appropriately positioned on the page. Your home-made paragraph macros — unless given explicit instructions — do not access this register. Thus, they will be unaffected by a preceding .RS command. This means your homemade paragraph macro may not format text with the desired left register to

:

i

i

margin.

you want to use home-made macros in conjunction with the -ms macros (or whatever macro package you employ) it is advisable to test the compatibility of your home-made macros with the macro package you use. This notion of compatibility will become clearer once you complete the final sections of this Module. If

342

Macro Construction

\

i

i

A Look (1)

(2)

The Break Command: nroff starts a new line you might want

It is

at

Inside Nroff

sometimes necessary

some

point in your text.

produce output something

to

to

make

sure that

For example,

like:

For most people, nroff can be very frustrating. Although a very powerful formatter, it is difficult to learn for the

it

is

fol-

lowing reasons: (a)

There

is

a large variety of very specific

commands which

each other in strange ways, and (b) The effects of commands are not immediately observable.

affect

The above output was produced with

the following input lines:

For most people, ./

nroff

can be very frustrating. Although it is a very powerful formatter, it is

difficult to learn

for the following reasons: .br

(a) There

is

a large variety

of very specific commands which affect each other in strange ways, and .br (b)

The

effects

of commands are

not immediately observable.

The hxeak (.br) command requests that a new output line be started. The last line of text before the break appears is entered but not adjusted to meet the right margin. Even though there is in the output line for more words, the line will be still room printed as it is. The text will not be adjusted to stretch from the the right margin by adding additional spaces.

left to

Note

that a .sp

command

will

accomplish the same effect while

also skipping a vertical space.

Filling filling

is

and the Break Function: As mentioned

in

Module

Five,

the process of joining short input lines together to create

output lines of approximately equal length. form this function?

How

does nroff per-

Macro Construction

343

(a)

Starting with the

and places (b)

nroff collects this line

file,

memory.

in its internal

many

of the words from this input line as Usually all of the words will fit onto the first output line. from the first input line will fit on the first output line

Next nroff enters

we

(because (c)

it

text line in a

first

as

type short lines, right?!).

all

Nroff then reads the next input line. If it contains text, nroff uses the text to continue filling the first output line. Soon the At this first output line contains as many words as can fit. point there are frequently several words lected input line left over. in the current

(d)

(e)

line.

next input

line.

If this line

contains

memory, and

more

no room

is

last

to include

col-

them

It is full.

In this case, nroff stores these

in (f)

output

There

from the

text,

words

it

is

in

memory and

added

to the

reads the

words already

nroff starts filling the next output line.

however, nroff encounters a format command as the next input line it must decide what to do with the text left over from the last input line (or lines) which it has stored in its If,

memory. There are two (i)

(ii)

possibilities.

Nroff could enter the remaining text on the next output line and then perform the command function (i.e. if nroff encounters the .sp command, it could print the remaining text, then skip a line), or

Nroff could first perform the command function (enter a blank line), while holding the remaining text in its memory. Then after performing the command, nroff could collect the next text input line, add it to the text it had remaining when it encountered the .sp, and begin the process of filling the next output line.

The possibility noted as (i) above is what actually happens when nroff encounters a command that causes a break to occur. The remaining text is entered as an output line, then the .sp

is

executed.

the .bp, .sp,

.ce,

.in, .ti,

.nf,

and

cause a momentary break in the

The second choice

Macro Construction

(ii)

command itself, commands all normally

In addition to the .br

is

the

.fi

filling

process to occur.

“no break”

condition.

(3)

The Two Control Characters: In Module Five you were informed that the dot (.) character— when it is the first character on a linelets

nroffknov^ that a

The dot

control character.

The other

characters.

command is

follows.

actually

In this role the dot

a

one of two possible control

control character

is

the apostrophe C).

apostrophe is the no break control character. cause a break, while 'sp will not. (4)

is

As

The

a result, .sp will

A

Demonstration of Breaking and Filling: The nroff requests bp, sp, ce, in, ti, nf, and fi can all be preceded by the apostrophe as well as the dot. With the control character they do not cause a break. Consider the following twelve input lines. They will be formatted twice — first with the sp request using the usual dot (.) control character, and a second time with the no break character: '

O

What

IS

a break?

These examples should help this

that

illustrate

nrofffunction is

often confusing,

but also very important. .sp

Let 5

a few

of the break function, using the old familiar space command fsp j try

tests

with both the break to

and no break

control characters

see what happens.

This input produces the following output:

What

is

a break?

function that

is

These examples should help

illustrate this

nroff

often confusing, but also very important.

of the break function, using the old familiar space command fspj with both the break and no break control characters to see what happens. Let's try a

The same

few

tests

input, but with the .sp replaced by a 'sp, produces a

different output:

What

is

a break?

function that

a few

mand to

is

These examples should help

illustrate this

often confusing, but also very important.

nroff

Let's try

of the break function, using the old familiar space comf sp J with both the break and no break control characters

tests

see what happens.

Macro Construction

345

Note that the use of a the word important (the

.sp causes the space to occur directly after

word preceding the command) and, in addition, causes a break in the filling process. The 'sp, however, does not cause a break in the filling process. Nroff filled and justified the first output line and had the words function that is often confusing, but also very important in memory, when it encountered the 'sp nroff request. Because 'sp is a no break command the words in memory were not entered as a partial line but kept in memory as the space (blank line) was entered. After the blank line was in place nroff collected another input line, added the text to the words already held in memory, and constructed the next very important output line. Thus the words function that is .. last

.

begin the next line after the space. (5)

The nroff Three Part

Title Line Request:

the formatter include three part

title

lines in a

the following input line was included in a .tl

The

'

For example,

if

be:

Wogowon

The following

nroff request, placed

duce a three part

Word

Butler

anywhere

in

your

file will

pro-

title line:

r Word 2' Word 3'

be placed on the left. Word 2 placed against the right margin.

Word

file.

file:

upon formatting would

Winston

'

possible to have

is

Winston' Wogowon' Butler'

resulting output

.tl

It

1 will

The four apostrophes

separate the

in the center

title line

and Word 3

into three parts.

What

two apostrophes will be placed on the left. The string of characters between the second and third apostrophes will be placed in the center, and text entered between the third and forth apostrophes will be formatted on the right. ever

is

placed between the

A Look (1)

Top and Bottom the (.pi)

Macro

Inside Several -ms Like

Macros

Module Five you were introduced to page length command. At that time you were informed

that although

346

first

of Page: In

you can specify the page length, nroff \s unable

Construction

to

do

anything

the top and bottom of pages without the help of macModule Nine introduced the .nr and .nr number at

HM

ros.

registers

RF

.ds

and the

.ds

LH,

string definitions.

CH, .ds RH, .ds LF, .ds CF and These commands affect various registers .ds

and can be used with the -ms macros margins and title lines. This

is

to

produce header and footer

way headers and footers operate. an example of how you can instruct nroff to create top

section

Included

FM

introduces

the

and bottom margins (complete with title lines) using your own home-made macros. This example also illustrates how string definitions can be used with your own macros in much the same way as they are used with the -ms macros.

(

2)

Begin a new practice file which we will call pages. This file needs to contain at least 100 lines of text, with no formatting commands. If you do not have such a file you can copy one of your existing

files,

increase

its

remove

all

commands from it, and finally copy $ command. Once the file

formatting

length using the :1,$

100 lines long and void of formatting commands, you should enter the twelve lines comprising the he and fo macros is

at

least

exactly as they appear here at the top of the file. ter

used

in line six ('sp |7/) is

The following

[Note; the

charac|

the pipe character.]

nroff requests will (a) Define the page header

macro

he to include space and a three part title line, (b) Define the page footer macro fo to include a space and a three part title line, and (c) Set a “trap” to call the header macro into action at the top of each page and the footer at the bottom.

.wh 0 he .wh -li fo .de he

'sp .51

A\'\\*(\h'\\*(ch'\V(rh' sp

|li

.de fo

'sp .51

.tl'WMlf'WMcf'WMrf' bp

Macro Construction

347

These twelve

lines will

.wh 0 he

have the following meaning

This request

nroff to perform a

tells

when (when)

specific function

on

ticular position

to nroff.

a page

(sometimes called setting

The .wh request arguments. The

is

a par-

reached

a trap).

used with two

is

first

argument

(in

this case 0) indicates the position

a page

(The

where nroff is supposed 0 position

to act.

of the

top

the

is

The second argument must be a call for a macro page.)

specifies

what

do

to

at

on

(he)

that

that position

(when the 0 position on each page is reached). The fact that this second argument must be a macro call— and



not an nroff request is significant;it is the reason why you cannot instruct nroff about what to

do

at

the top and

bottom of pages without using macros.

.wh

-7/

fo

This call

.wh request the fo

(footer)

page position. The

instructs

macro

nroff to

the -7/

at

-7/ position

is

one

inch up from the bottom of the page.

Any (-)

position specified with a

number

is

a

relative

based on the page length.

minus

position

The

-7/

on a three inch page is two inches from the top, while on a ten inch page this position would be nine inches from the top. position

.de he

This

begins

the

definition

of

the

header macro that will be called at the top of every page. This automatic calling was specified with the .wh 0 he request.

348

Macro Construction

s

'sp .5/

The

first

action of the header

macro

be to space down one half of an inch. The no break control character is used so that text remaining in

will

nroff"

internal

printed

after

memory

be

will

the 'sp action

is

per-

formed, not before. Thus it avoids having a break before the top of each

new

The

page.

text

is

carried

into

the body of the next page. .tl

'\\*ilh'\\*(ch'\\*irh'

This

Because this title line is included in a header macro that is called at the top of every page it will produce the same header on all is

a title line.

pages.

To make

macro useful beyond

this

a

single paper the particular phrases to

be placed in each position have not been specified. Instead, characters such as \\*(lh in the left title position are included. The \\*( informs nroff that: (a)

A

two

string follows (b)

name

character

Somewhere

a

(.//?);

else

the

in

two character string (such as .ds

for

Ih

is

file

the

defined

Authors' Pets)\

and (c)

The two be

character

replaced

replace the

1

7/

This

A?

by

(Authors'

definition

'sp

name should the

string

Pets

will

//?).

request again uses the no

break control character to avoid causing a break before the top of each new page. The symbol can be used with any nroff lequQSi that includes a |

numeric value.

It

is

known

as

the

absolute position indicator and, in this

Macro Construction

349

case, informs nroff to space

down

to

the position one inch from the top of

page

the

one inch from

down

of spacing

(instead

the current position

on

the page).

This

..

the

indicates

end

of

the

he

definition. .de fo

This line begins the definition of the iooter macro which, in response to the .wh -li fo request, will be called whenever nroff reaches a position

one inch from the bottom of every page.

'sp

.5/

The

first

down

space

'\\*(lfA\*(cf'\\*(rf'

.tl

A

action of the fo a half of

title line will

macro

is

to

^

an inch.

be placed

at this posi-

on the page. The title line will consist of up to three parts: a left, To be center, and right footer. included in one of its three fields a string of characters must be specified as a string definition. Such string tion

definitions

macro bp

The is

are

placed following the

definitions in your

final action

after the title line

that the

file.

of the footer macro

cause a page

to

!

is

i

break to occur printed.

Notice

no break control character

is

i

i

used. I

This ends the definition of the fo

i

macro.

(3)

Using String Definitions With Your Own Macros: At this point you can use the .ds request to specify strings to be used in your header and footer title lines in much the same way as you do with the -ms macros.

350

Macro Construction

:

'

i

Enter something

like the following requests in

your pages file (place the following requests before any text but after your macro definitions):

(4)

.ds Ih

left

.ds ch

center header

.ds rh

right

header header

.ds If

left

.ds cf

center footer

.ds rf

right footer

footer

Testing the Page Control Macros: At test your new page control macros.

You can send your Shell command (do not

this

time you

may want

to

be formatted with the following include the -ms flag in your command to

file

line):

nroff

(5)

flenamel

\

The Strange Paragraph Reset Macro: macro package

page

If

(or read the material in

you regularly use the -ms Module Nine describing

these beasties) you have probably discovered that the paragraph

macros do a lot more than format paragraphs. In fact, all paragraph macro calls in the -ms system not only do what you expect (in the way of indentation and spacing) but also call a series of nroff requests that look something like the following .RT macro: .de

RT

.sp

.ne 1.1 .in

0

.ul

0

.ce 0 .ft

R

\\n(LL .ps \\n(PS .vs \\n(VS .II

The .RT macro all

-ms

is

known

paragraph macros.

as the It

ReseT macro and

turns off underlining

is

called

(.ul

Macro Construction

0)

by

and

351

centering (.ce 0), resets the font to Roman (.ft R), and resets the line length (.11 \\n(LL), point size (.ps \\n(PS), and the vertical spacing (.vs \\n(VS) to the values stored in the LL, PS, and VS

number

registers.

This

why

is

placed before a -ms paragraph

(#the

will turn

just set

a .ul request will

macro

call.

have no

effect

if

The -ms paragraph macro

request for underlining even though you have

to underline.

it

number

which controls the point size (.nr PS) request does not take immediate effect but must wait until after the next paragraph macro call. The change to the number register will not be read by nroff until it encounters the next paragraph macro. This is the reason why you must place a -ms paragraph macro call at the beginning of your file, after any number register requests that you use. That paragraph macro is necessary as it will establish the -ms defaults for these number registers. It is the initializing macro. Similarly, a

(6)

change

in the

register

Viewing the -ms Macros: For those of you who are interested, the -ms macro package is contained in a file with the following full path name: ! usr ! lib ! tmac ! tmac.s

To view

this file enter the

vi

If that

/

command:

command sequence

does not work enter the command:

whereis

Use the the

lair

®

usr / lib / tmac / tmac. s

tmac.s

®

pathname returned by the whereis command of the -ms macro package. full

to visit

Spend some time browsing through the -ms macros, and see if you can interpret how some of the commands actually perform their functions.

complex topic of macros. You may want to return to this Module after you have completed the remaining material in this book and give it a second reading. As you now know, the internal workings of macros decide how your formatted paper will appear. Your

The

352

quiz which follows concludes your introduction to the

Macro Construction

macro— and occasionally construct command does not exist— can make

ability to select the appropriate

your own when the necessary your formatting experiences both more effective and more

satisfy-

ing.

A

Final Quiz:

Describe the effect of the following nroff requcsi:

(a)

.tl

'jerry 'and 'meredith'

Consider

(b)

a

file

named

test,

which contains the following

six

lines:

Hi

.de .ce

\$1 • •

.Hi there

How

are

If this file

you?

was sent

to nroff to

be formatted, what would the

resulting output look like?

What

(c)

effect will the

command

'br

have

if

entered

in

a text

file?

Suppose you placed the following nroff xtquQsX at the top of a text file. What effect will it have on the resulting formatted

(d)

output?

.wh

Answers: and

in

(a)

A

bp

three pari

title line will

appear with the word

the middle, and mcredith against the right margin,

would not appear the

-1

macro

ing, as the effect.

in

(d)

on the

left,

The word “there”

the output, due to the presence of a \$1 instead of \\$1 in

definition; the line

break

(b)

./'em’

command

“How

are

you?” would be centered.

(c)

Noth-

with the no break control character will have no net

Nothing, as only macros can be used as arguments to the .wh

request.

Macro Construction

353

New Command

nroff Requests

Function

Begins macro

.de

Ends macro File will

XX

with two

macro name.

character

.so

Replace

^^finition.

named

definition.

file,

containing macro definitions,

be sourced into current

file.

Prints a three part Vt\e line.

.ti

\n(

XX

Reads

XX

Replace

XX

value stored in

in

with two character

number

register.

number

register

string

register.

name. \*(

XX

Reads

in

Replace

string

XX

stored

in

XX

with two character string register

name.

Reads

in first

argument

to

macro

Absolute position indicator.

No

354

Macro Construction

break control character.

call.

Module Twenty-One Utility

Programs

• CD02

nr

Introduction Through the

first

twenty Modules you have seen

how UNIX

can be

used to create and edit files, locate spelling errors, organize a directory system, communicate with other users, and line print or typeset all kinds of files. The remaining Modules will describe in some detail how UNIX can format form letters, tables of contents, tables, equations, and maintain a bibliography. The final Module briefly introduces several additional UNIX resources which can assist

with your editing, programming, or writing tasks.

What more can UNIX do? Quite you

will

meet programs which

a bit, actually.

will locate files,

In this

compare two

Module files to

they are the same, translate specific characters in a file into other characters, and sort lines alphabetically. And these are but a few of its various capabilities. see

if

Prerequisites To

utilize the

spell ‘‘utility”

information

in

this

Module you should be

and use the information presented

in

the

able to

first

eight

Modules Fifteen (The UNIX Directory Structure) and Twenty-Two (Commands, Files and Directories) are recommended.

Modules of

this

book.

Module Five

is

optional, while

355

Objectives of this Module you should be able

Upon completion (1)

Automatically remove

(2)

Sort a

(3)

Translate into a

new

file;

string or range of characters;

(5)

Compare two

all

redundant

common

Combine

a

occurrences of a string or range of characters

all

Remove

(6)

commands from

according to an alphabetic or numeric rule;

file

(4)

or

formatting

all

to:

files

lines

and find

from

a

file;

lines that are

unique

to either file

to both;

the above actions into useful ‘‘pipelines.”

Procedure This Module

will

introduce several

The format used

processing.

new programs

useful for text

to describe these utility

programs

will

from the approach used in other Modules, and will be similar to that used in the UNIX Programmer's Manual. The final section will present an example of how these programs can be joined differ

together to accomplish a complicated task.

deroff

NAME

(and function)

deroff



remove

nrofif, troff, tbl

SYNOPSIS (how command deroff

[

-w

]

is

and eqn commands

entered; brackets identify options)

filename

DESCRIPTION The

Shell

command deroff

will

output to the terminal a copy of filename, minus

instructions.

356

filename

Utility

Programs

all

formatting

To have the output Shell command:

not by lines but in single words, use the

listed

-w

deroff

filename

®

PROBLEMS remove

deroff does not always

subtle formatting constructs.

sort

NAME

(and function)

sort



sort a

file

SYNOPSIS (how command sort

[

-0 -d -f -r

]

entered; brackets identify options)

is

+posl

[

]

[

— pos2

]

filename

DESCRIPTION The

sort

program

will alphabetically

and/or numerically sort

lines

no +posl or -pos2 is specified) sort arranges the lines of a file in alphabetic and numeric order by comparing the first character of each line in a file. For example, the of a

file.

following

In

is

its

form

basic

(if

the contents of a

.nr

PO

file

named

test:

21

.LP This

is

file to

a be sorted

by the sort routine.

nf 11223 12133 13100 13101



Jt

Utility

Programs

357

The following

sequence would sort the above text and have the resulting output displayed on the terminal: sort Shell

sort

The

resulting sorted material

®

test

would look

like:

.LP .fi

^nf .

nr

PO

2i

11223 12133 13100 13101 Th is is a by the sort routine, file to

be sorted

Note the sorting order: symbols were listed first (periods), then numbers, followed by upper and then lower case letters.

Changes the

file

in

the sorting routine are possible.

named

test

and place the output into sort -0

The

output

The following will sort a file named output:

test

output to the file named as an argument to the option {output) instead of directing its output to the standard output. This command will accomplish the same -0 option tells sort to direct

its

result as:

sort

To

test\

>

output

sort only those lines beginning with a letter, digit, or blank

{dictionary order)

you would use the sort -d

Whatever

command

line:

flename

do not begin with a letter, digit, or blank will be placed at the bottom of the output. Thus the special characters, A/ro# requests, and macro calls would be removed from the sorting and placed as residue at the end. Utility

lines

Programs



If

both upper and lower case

letters

should be sorted together

{folded together), use:

sort -f

filename

®

The order of

sorting can be reversed (so that the line which would normally be sorted as the first line would instead be sorted last) by: sort -r

In addition,

the file(s)

character in each line.

filename

®

need not be sorted based upon the first Most lines of text or numeric data can be

considered as being composed of separate fields. A field is defined as a group of characters separated by white space (a word, a number, a series of letters, etc.). Thus the following line can be considered as consisting of six fields:

Name

Fido Nerfball Age 47

B.

The word Name

is

the

first field,

and Nerfball is the fourth and the number ^7 is the

field.

sixth.

B.

is

the second, Fido

The word Age

is

Suppose you had

is

the third,

the fifth field, a

hundred

line

with each line containing the same five fields of information (one line for each individual). You could sort the file according to

file

last

name

(4th field) with the

sort

The

-1-3

tells

command:

-1-3

filename

® and thus base the you wanted the sort to

sort to skip the first three fields

on the fourth and following fields. If be based only on the fourth field you would use the command:

sort

sort

This

command

-1-3

translates as,

ing the third field

filename

®

“base the sort on the

and preceding the

fifth field (the

field (s) follow-

fourth

field).

PROBLEMS sort

only sorts

lines.

It

cannot easily sort records consisting of

multiple lines based on a field

in

only one of the lines of the

record.

Utility

Programs

359

SEE ALSO comp

deroff, uniq,

NAME tr

(and function)



translate input characters

SYNOPSIS (how command tr

[

-c -d

-s

]

[

is

string 1

]

entered; brackets identify options) [

string!

]

filename

DESCRIPTION With the

command you

tr

into another.

characters.

can translate one string of characters The hyphen (-) can be used to specify a range of

For example the

A-Z

tr I

will translate all

command

space

a-z

filename

I

uppercase characters to lowercase.

SEE ALSO sed

uniq

NAME

(and function)

uniq

— remove

redundant

SYNOPSIS (how command uniq

[

-u -q

]

is

lines

from

a

file

entered; brackets identify options)

filename

DESCRIPTION Often when sorting or making an index you wind up with a file which there are duplicate lines. The uniq program will assist

360

Utility

Programs

in in

where there are several copies of identical lines. Note! duplicate lines must be adjacent when using uniq. If duplicate lines are not adjacent you should first sort the file and then use situations

uniq

to deal with duplicate lines.

To produce an output of

single copies of

which the second copy of any line is deleted) use the following Shell command. Output will consist of one copy of all unique lines and one copy of all duplicated lines: uniq

The

Shell

lines

(in

filename

command uniq -u

will

all

examine filename and

print

filename all

lines that

appear

in the file

only

one time (unique lines only). Output consists only of one copy of unique lines. Duplicate lines are ignored. Additionally, the

command: uniq -q

will

examine filename and

(duplicate lines only).

no matter how often no copy of all unique

find only those lines that are repeated

then print a single copy of each line, was repeated in the file. Output consists of

It it

®

filename

will

lines

and one copy of

all

duplicated lines.

SEE ALSO sort,

comm

comm NAME. (and

function)

comm — compare

two

SYNOPSIS (how command

comm

[

-

123

]

files

is

entered; brackets identify options)

file I file 2

Utility'

Programs

361

DESCRIPTION The comm program compares two

line

files,

by line and separates

the lines into three categories: (1)

Lines found

(2)

Lines found in file2 but not

(3)

Lines found in both

The

Shell

but not in file2

in filel

and

files.

command:

comm

file2

filel

perform the separation and then print

will

To suppress the printing of include the number 1 as a flag

comm This in

in filel,

will result in

both

files.

To

list

the

command

Those

lines

lines

found

in the

command

-1

in filel

and not

file2

sequence:

filel

filel

found only

common

in filel will

both

to

files,

not be printed.

use the -12

flag in

sequence:

comm

filel

three categories.

the printing of those lines found in file2 only or

only those lines

With the -23

all

flag the

-12

filel

comm command

(for instance the

names of

all

file2

will

produce a

students

who

list

of lines in

are in a doctoral

program) not in file2 (names of all students whose registrations were blocked). The resulting list are those names in filel not in file2 (students who are in the program but whose registrations were not blocked). Such a list would be created by:

comm

-23

SEE ALSO sort, deroff, uniq,

362

Utility

Programs

comp,

diff

filel

filel

An Example of the Wonders of Piping Not for Plumbers Only The

five utility

The

final step in this

programs introduced in this Module can be used together to transform a text file complete with formatting commands into a relatively short list of ‘‘unusual words.” process

compare

of words consisting of every word found in one of your files with a list of common English words. This second list of common English words exists on most UNIX systems in a file with the full path name lusrflibleign. The comm command introduced in this Module is used to compare the two files and identify all words found in one file but not in the is

to

a

list

Certain constraints must be met, however, before the two can be effectively compared with the comm command: (a)

other. files

Both each

files file

must be sorted should be on a

ascending sequence; (b) Every word in line by itself; (c) Every word in each file in

can occur only once; and (d) Because comm will treat a word beginning with a capital letter as different from the same word not capitalized, all characters must be translated into lower case.

(1)

The

actions necessary to

formed within

meet these constraints can

a single Shell

command

all

be per-

easier— and for many purposes more useful — to perform these actions in two steps, however. For these reasons, we will first illustrate the twostep method and then present the one-step method.

(2)

line.

It

is

Preparing the File of Common English Words: Before this file ilusrllibleign) can be compared to one of your files it must be sorted into ascending sequence. This is done with the following command sequence: sort

This

command

(containing

/

usd lib/ eign

> common

line will create a sorted

the

words) and place

one-hundred and

new common

®

copy of the /usdiib/eign

fifty

most

common

file

English

your current directory. (Later on this file can be expanded as you discover other frequently used words. Don’t forget to resort your common file after making additions, however.) this

file

into

Utility

Programs

363

(3)

Preparing Your Text File: Before your text file can be compared to your new common file several actions must occur. The file must be stripped of all formatting commands, and each word must appear on a line by itself. The words must be sorted into ascending sequence, all characters translated into lower case, and all redundant words must be removed.

The following command

line will

command

deroff

-w filename

line,

tr |

All formatting

but attempt to decipher

A-Z

sort

a-z

all

these actions and

(An explanation of each

do the actual comparison. the

perform

|

\

commands

in

uniq

|

comm

filename are

yourself

it

-23

first

-

step follows first):

common > unusual

removed by

droff,

then put the remaining words on individual lines (-w). The output from deroff will be passed on to tr, which will convert all upper-case letters to lower-case. (This step is required by the uniq program.) This material is passed to sort which will put these words into alphabetical order. The output of the sort program is passed to uniq, which will discard all redundant lines (words) and then hand its output to comm. The comm command then compares this output (or input, depending on your point of view) to

which

will

named common which contains a sorted list of the 150 most common English words. The output from comm (the words in filename that are not among the 150 most common English words) will be placed in a file called unusual. Whew!! the

file

The

file

named

unusual

will

of the words in filename of very common English words.

contain a

list

which were not in the UNIX list Such a list could be used to create a glossary or index (and was fact how the index to this book was generated).

(4)

The One-Step Method: The above two-step procedure can be consolidated into a single step by using the semi-colon

This special Shell character

is

to

be performed in sequence.

If

two

command

following Shell

command

sort otherfile

Utility

Programs

used to separate two

lines are separated

pleted before the second

364

in

>

one begins.

by a

;

the

(;)

character.

command

first will

lines

be com-

For example, consider the

line:

tempfile\comm -23

file tempfile

\

Here, sort

will first sort

put into a

file

name

then compare

will

the

tempfile.

file

named

Once

and place the out-

otherfile

this process

is

complete,

comm

file to tempfile.

This procedure has one potential drawback. You are left with a tempfile that you may never again use. You can avoid this problem through the use of two additional UNIX features. The first involves the use of the UNIX iemiporary directory. The full path name of this directory is

is

The

/tmp.

/tmp directory

periodically cleaned out by the

convenient place to deposit a

file

is

“powers

that

publicly accessible

Thus, it of only temporary use.

is

that be.”

The second feature is the $$ symbol. It can be used unique name to a temporary file. The command line sort filename

>

and is

a

to assign a

/ tmp/ %%

filename and place the output into a file with a numerical in the /tmp directory. (For those who are interested, this

will sort

name number (5)

With

is

the process ID of the parent Shell.)

as an

introduction, you are following Shell command

this

The features to work and accomplishes our finale.

We

display the

the sequence.

Do

not press

®

command

I

ready for the grand line puts all these UNIX

task

all in

one

step.

(Note:

two lines, owing to the length of This is, however, one continuous command line. until the entire command has been typed):

> comm

sort /usr/lib/eign sort

now

uniq

|

line as

/tmp/%%\ deroff -w filename -23 - /tmp/%% > newname

Utility

|

tr

A-Z

a-z

®

Programs

365

Module Twenty-Two

Commands,

Files,

and Directories:

or

Paths, Bins, and Yellow Brick

Modes

Introduction

We

have stated

in prior

UNIX

Modules

that

UNIX

stores information in

even your terminal. This is truly a remarkable feature, and one that allows you to and the standard input tie together (in conjunction with the pipe and output) Shell commands in an infinite number of combinations. This ability is what makes UNIX so flexible and powerful. files.

In practice

treats everything as a

file,

\

You have created and worked with your own files, but what about the commands that allow you to go about your UNIX tasks (vi, nroff, cp, page, and Ipr, to name but a few)? They also exist in files.

We

bins.

This trek

would

like to will

guide you into their lair—the UNIX storage

allow for a discussion of

how

one named page) can act upon another when you enter the command page filename). (like the

it

is

file

that a (as

file

occurs

Prerequisites To use

this

Module you should have completed

the material in

Modules One through Eight (Five optional). Fifteen: The UNIX Directory Structure (essential), and Sixteen: Account Management.

366

Objectives Upon completion (1)

Use

perform

Describe

how

a function);

be able

will

modes

permissions and

file

(able to (2)

of this Module you

to

make

to:

a

file

executable

and

directories, bins,

and search paths

affect

your

interactions with UNIX.

Procedure These procedure steps are presented in two sections. The first section explores modes, permissions, owners, and executable Shell scripts. Section two takes you on a tour of the UNIX command storage bins and discusses how the Shell “locates” a command.

coo

wr

Modes, Permissions, Owners, and Executable Shell Scripts

You need

to begin the exercises in this

directory.

To

insure that you are

Home

cd

Module of the

(1)

Fifteen: The

Home

Module from your Home type:

®

UNIX Directory Structure discusses the concept

directory.

Creating an Executable File: An executable file begins life the same as any other file. Begin a new file by entering the command: vi

(2)

22

facts

®

Place the following six lines in this,/^c/5

echo echo 'My current

directory

file:

is:'

pwd echo echo 'The files

in this directory are:'

Is

Commands d

Files

367

^

When

(3)

finished, write the

memory

into the

file

of the Beast and

return to the Shell.

From

(4)

the Shell type:

®

facts

What happened? You

receive a note stating:

facts: Permission denied.

facts This note lets you know that the Shell tried to execute the but found that it did not have “permission” to execute it. The file at this point is not executable.

the nature of this beast called an executable file? Well, the Shell program page is a good example of an executable file. The Shell can apply the contents of the page file to almost any file

So what

is

you have created, resulting

that

on the screen. The

ex

being displayed

also an executable

is

file.

executable, the Shell has been given permission to per-

If a file is

form the actions

As

line editor

in the specified file

UNIX

specified within the

file.

concerned the file facts is still only a nary, non-executable file. This will soon change ....

(5)

far as

is

Permissions:

File

From

the

List

the Shell enter the

sign, lower case

filenames

command

space

Shell

-1

(lower case

Home 1,

command

space,

Is

-1

will give

you

a long listing of the files

Among

other things, this long

like the following

files.

should be displayed on your screen:

total 9

drwx —rw —rw

—rw —rw 368

Commands &

minus

®

include the permissions attached to your

Something

s,

directory.

I

located in your current directory. listing will

your

1):

Is

The

in

plain, ordi-

Files

2

login

1

login

1

login

1

login

1

login

544 Nov 13 17:04 Study second 6100 Oct 12 11:32 1452 Sep 1 11:58 experience 1064 Sep 2 21:14 first 93

Dec 19 10:32

facts

Each

the long listing for one file or directory in your current Each long listing consists of several parts.

line

is

directory.

The

(a)

first

and

part

10 characters long {drwx

is

specifies the ‘‘permissions”

attached to each missions field.

The second

(b)

file.

We

The

(c)

the

part of the listing

number of links the moment.

(in this

The fourth

(d)

we have

case

also as i\\Q file

mode)

portion as the per-

number

a

is

just entered the

portion of the listing

and

file

the login of the

is

is

which of no

(7 or 2)

attached to the

third part of the long listing file

)

will refer to this

identifies the

concern for

(known

or (-rw

)

word

is

owner of

login).

the length of the

file

in

bytes.

The

(e)

date the

of the

The

(f)

last altered is

entry

is

the

file’s

2

#

Permission Fields

For the

in a

Listing

Nov 13

544

File’s

size in

Date of Last

Owner

bytes

Modification

the important feature

10 characters on the

Long

login

of

Links

moment

fifth part

name.

Information Fields

drwx

displayed as the

and

listing;

last

was

file

left

of each

line.

is

Study

1 7:04

Filename

the permissions

field:

the

Each of the 10 positions has

a particular significance.

The

first

tory, or

directory first

facts)

position indicates whether the listing

some other UNIX (i.e.,

a file), will

beast.

A

most often appear is

(—

file,

first

-

a direc-

for not a

in this position.

in

not a directory.

directory, as evidenced by the d in the

sions

for a

d for directory, or

character in the permissions field indicates that facts

is

the case of the

The

file

Study

The file is

a

position of the permis-

field.

The next nine

characters can be considered as three fields of three characters each. For now we need only concern ourselves with the

Commands d

Files

369

of these three fields following the directory character. three characters determine what you (the owner of the

first

directory) can

do with

These file

or

it.

of these three positions is filled with an r the owner has — read permission and can view the contents of the file. A (minus sign) indicates that the owner does not have read permisIf

the

first

sion.

the second of these three positions is a w the owner has yfrite permission and can make changes in the file. A minus sign in this position would indicate that the owner would not have write per-

If

mission.

The

third position indicates

whether the

file

can be executed.

An

X indicates that the owner has execute permission; a minus sign means that the file does not have execute permission. w, or x in a permission field indicates that the associated permission is granted; a — indicates that this permission is not granted. In

summary, the presence of

For now

named (a

-

a

r,

the permissions field associated with the file indicates that it is not a directory line -rw

let’s interpret

facts.

The

and that the owner (you) has both read and

in first position)

write, but not execute permission (rw- in positions 2-4).

Execute permission means that the file is a Shell script or a compiled program and that it has permission to perform its function. (An executable directory allows you to look for files in it.) Whenever you create a file it automatically has read and write — but not execute— permission. To add execute permission to a file you

must change (6)

its

Filemodes: You cutable. Type:

mode.

will

now change

chmod

the

mode

700 facts

of facts to

make

it

exe-

®

The command chmod stands for change mode. The number 700 gives the owner read, write, and execute permission for the file. The 700 can also be considered to have three fields (7 0 0). Again, we are only concerned here with the first field (the number 7), because this field determines what the owner can do with the file.

370

Commands &

Files

The number seven in the first field is actually a “composite” number (sum) constructed from the following “primitives:” (a)

1

grants execute permission

(b) 2 grants write permission (c)

4 grants read permission.

These primitives can be added together

to grant

any combination

of permissions.

The

basic permissions for the file’s

owner

are:

000 grants no permissions 100 grants execute permission only

200 grants write permission only 400 grants read permission only

The sum of 100 + 200

=

400 and execute permissions would -f-

all

700 would mean that read, write be granted.

300 grants execute and write permissions (100 + 200); and 500 grants read and execute permissions (100 + 400). The permission of 600 grants read and write permissions (200 + 400). These mode changing codes relate to permissions to the owner of the file. These three numbers (1,2, and 4) can be used to express the eight possible states involving combinations of these three binary conditions (yes or no for execute, write, and read permissions). As a point of interest, no other combination of three single-digit numbers yields this continuous and unique scale for binary combinations. Additionally,

To check on whether affected the filemode

the

facts enter the

Is

Note the presence of the in

So what does

-1

letter

the permissions section.

cutable.

command sequence chmod

this

x

command:

®

facts

in the position third

This x

700 facts

tells

you

that

./am

from the is

now

left

exe-

do for you?

Type: facts

® Commands &

Files

371

This lime you are treated to the display of the name of your current working directory, along with a listing of all files in your current directory. This information is the result of the two Shell commands placed within your facts file. No big deal (although it beats a poke in the eye with a sharp stick), but

any

file

owner must change (9)

With

You

commands

containing Shell its

made

can be

illustrates

it

how

executable: the

filemode to 700.

filemode of 700 a file becomes, in effect, a Shell command. can execute the contents of the file by simply typing its name. a

A

Second Executable File: As another example, you can create an executable file which will cause the Shell to first change directories to a specified sub directory and then start the process of visually editing a

(10)

file in

that directory.

sure you are in your Home directory. Once there you should create a file named go containing only the following 2 lines. (Substitute the name of one of your sub directories for directory

Make

and the name of

a

file

located in that directory for filename):

cd directory vi [filename

Return to the Shell and change the mode of the go Then from the Shell type:

file

to 700.

®

go

went according to plan you should be moved to the specified directory and filename should present itself for visual editing. If all

(12) (11) Creating a Bin: fully

more

You may

interesting)

wish

later to create additional

executable all

now. From within your

Home

facts into

Bin

sequence:

Commands &

Files

useful to create a files.

Let’s do this

®

your Bin directory.

mv 372

is

directory type:

mkdir

command

It

of your executable

directory (bin) to hold

Next relocate

files.

(and hope-

facts Bin

®

Use the following

Once

(13)

again enter the

command:

®

facts

The Shell replies “facts: Command not found” because it does not know where to look for the new facts command. In the next section of this Module you will learn how to include your own Bin in the search path followed by the Shell when looking for executable files.

Uses of Executable Files: The two example executable files presented here were designed to allow you to practice constructing files and changing their modes. In fact the tasks which these two files accomplished are more efficiently handled with the alias command. Executable files are normally used for more complex tasks not easily solved by an alias

(14) Yes,

(a)

command.

Another Quick Review:

What command

gives you a long listing of your filenames,

including the permissions attached to each (b)

What permissions missions

(c)

field (-r-x

file

(include the

What would had changed mission?

Answers:

(a) Is

the permissions field for a its

mode

(b) read

-l

chmod 700 filename

(d)

in

your

file

look like after you

to include read, write,

and execute per-

and execute but not write permissions

-rwx

Bins,

Log onto your UNIX account. you are located

to

mode number)?

UNIX Commands, Storage (1)

with the following per-

change a file’s permissions include read, write, and execute permission for the owner

of the

(c)

file

)?

What command would you use to

(d)

are granted to a

file?

Home

If

and Search Paths

already logged on,

directory.

cd

make

sure

Type:

® Commands

Files

373

(2)

In

Module

Fifteen you learned that

(dot dot)

..

is

the

UNIX name

your current directory. Ever wonder who or what exists above your Home directory? Here’s your chance to find out. Type:

for the directory located immediately above

cd

You

now

are

located one level above your

several deep breaths— the air

To determine

(3)

(now one

®

..

level

is

(4)

Root:

the contents of your current working directory

above your

Your

You

directory

Home

directory) type:

®

will

login will

need

among

be found

to use a

UNIX

‘'special

the

list.

character” for the next

move. Type: cd / space

The

(Take

of the other users of your UNIX system should be

logins

displayed.

directory.

pretty thin at these elevations.)

Is

The

Home

UNIX name

®

I

“root” directory (in addition to being the character used to separate directory and filenames when you use a full path name). Root is, curiously, located in the UNIX penthouse. All files and directories are located below root. /

is

What

(5)

the

files exist in

for the

the / {root) directory?

®

Is

The

Type:

of filenames probably does not look too exciting. the names listed should be the usr directory, however.

(6)

list

Change

directories to the usr directory.

cd

(7)

List the contents of the usr

usr

One

of

Type:

®

directory with the

Is

command.

Anything look familiar? If you are a UCBerkeley-type, your attention may be drawn to the directory named ucb. 374

Commands &

Files

To explore

the contents of the ucb directory.

List the filenames in this directory.

(9)

(10)

®

ucb

cd

Type:

Recognize any files? The names of Shell commands used to work with UNIX should now appear. (We told you this was pretty heady stuff.) If

the directory ucb did not appear, type: cd

The ucb

(or ucb/bin) directory

taining the files that are Shell

®

bin

is

one of the UNIX

commands. The

directories con-

directories

which

hold UNIX Shell commands are referred to (in UniJargon) as bins. The only difference between a bin and a garden variety directory is (11) that bins contain executable files. The term bin is derived from the fact that most of the executable files stored in these UNIX sys-

tem

directories are in a

To

find out

what

bitmy format.

a binary

file

®

page ex

You should

command:

looks like enter the

receive a note indicating:

(12)

ex: Permission

The commands

Denied

stored in the ucb directory are contained in

that are executable

but not readable.

commands you cannot

view the

files

Although you can use these

files that

contain

them

(this

is

part

of the UNIX security system).

For the next directory.

To

(13) Discovering

commands (known

you need to be located in your Home you are there enter the cd command.

activity

insure that

Your Search Path: You now know are

as bins).

actually

The

executable

files

stored

that

most UNIX

in

directories

bins that the Shell searches and the order in

Commands &

Files

375

which they are searched

named

variable

Sixteen)

used to

is

set

From

path.

is

The

determined by the setting of the Shell

command

set

used to control the search path in the the Shell variables ignoreeof and noclobber.

command:

the Shell enter the

set

Module

Shell

of the Sixteen).

®

command, used without arguments,

Recall that the set settings

Module same way it is

(introduced in

list

the

your account (see should look something like the follow-

variables

Your

will list

attendant

to

ing:

0

argv

cwd /pbjmpb/Book/Minis history

25

home

/pbjmpb

ignoreeof noclobber path (. /usr/ucb /bin /usr/bin) shell /bin/csh

0

status

term flOO user pbjmpb ignoreeof and noclobber variables should be familiar. For now note the information that follows the word '‘path,” as this is how your search path is currently set. When you enter almost any com-

The

exceptions are alias, set, and cd), the Shell will start its search for an executable file with that name in the first directory For example, suppose you type the listed in your search path.

mand (some

Shell

name of the executable file you created Module). The Shell will begin looking in the current If a file with that name (facts) is not found in the

command

earlier in this

directory

(.).

facts (the

current directory, the Shell will next check the /usr/ucb bin. If The last stop is still unsatisfied, the Shell goes to the /bin bin. /usr/bin. Each of these bin names is preceded by a / because they

more

below the root (/) directory. Finally, if the Shell cannot find the command in any of these locations (and it would not find facts with this search path) you will be greeted by the now familiar reply, ""Command not found.""

are

all

located one or

Commands &

Files

levels

377

command

can exist in several different forms, each in a file with the same name, but located in different These forms will be the command as it evolved over bins. different versions of UNIX. (The process of storing different files with identical names in separate directories was discussed in

On most UNIX

Module

systems

Fifteen.)

a

The most commonly used

bins for BSD

UNIX

are:

/usr/ucb, /bin, and /usr/bin. very important, because the Shell discontinues its search upon locating the first instance of an executable file with the right name. It does not matter, to the

The order

Shell,

if

in

which bins are searched

is

that filename also exists further

down

the path.

It

does,

however, matter to you. The search order can determine which executable file is found (and therefore used by you).

Your Path: Remember the file facts located in your Bin directory? An easy way to advise the Shell about executable files

(14) Setting

located in your Bin

is

to set

your search path to include a

trip

through Bin. Go ahead and advise the Shell of the existence of your Bin directory with the following Shell command sequence: set

=

path

" / Bin)

/usr/ucb /bin /usr/bin

(. I

space

I

j

I

your path the Shell may (15) be unable to find any Shell commands. Should this happen you "" Command not found"'' message upon typing in will receive the your Shell commands. Fear not— you need only logout and log back in again. Order will be automatically restored to your search Note:

If

you make

a mistake in specifying

path.

Now

type the

command facts

®

Did the Shell locate and execute the commands contained within If not, carefully reset your search path and this executable file? attempt this step a second time.

(16)

378

procedure step 14 has only a temporary effect — the Shell will forget about your Bin bin when you log out. You can permanently remind the Shell by inserting the above line in your .login file.

The sequence you entered

Commands &

Files

in

Double Warning: your

If

you

err in entering the following text into

you will continue to receive the ''Command not found'' message to your Shell commands. Logging out and back in again will not help. You will have successfully piloted your search path into a black hole, and you will need to perform the following three steps to escape from this situation: (a) Reset your path from the Shell (Enter from the Shell the set path command sequence noted in Step 14 above); (b) Re-edit your .login file to include the correct path; and (c) Again enter the source .login command. (a)

.login

file,

up your .login {dot login) appears on the screen find the Call

file

Once

for visual editing.

line

it

beginning with the words

set path.

(b)

append the following characters

Carefully

at

the end of your

search path (inside the right paren):

"iBin Without these characters added to your path

it

look simi-

will

lar to this:

set

path

=

(.

/usr/ucb /bin /usr/bin)

With these characters added to your path

it

will

look similar

to this:

set

(c)

Return Note:

path

=

to the Shell

If

and type the source

.login Shell

command.

the set path line does not appear in your .login

just insert the following line

set

path

=

somewhere

in

the .login

space

I

I

file

file:

^ ! Bin)

/usr/ucb /bin /usr/bin

(. 1

(17)

^ ! Bin)

/usr/ucb /bin /usr/bin

(.

1

and Modes: As you now know, the permissions attached to files and directories determine w'ho can do what with each file or directory. We have already discussed the

More on

File Permissions

role of the first four positions in a permission field: the first charac-

whether the file is a directory, and the next three characters indicate what the owner of a file can do with it. The second set of three characters determine the same permissions ter

indicates

Commands &

Files

379

and execute) for users in iht file owner’s group. Just who belongs to a group can be specified by the owner: see the UNIX Programmer’s Manual entry for newgrp. The final set of characters represent the permissions granted to everyone else (others). (read, write,

most cases these three permission groups (owner, group, others) will have the following meanings to you: In

owner’s permissions will determine what you can do with

The

(a)

the

files

you

create;

(b)

Group permissions will determine what people in your group can do with files. For instance, files containing Shell commands (such as the ex file— containing the line editor— that you attempted to view earlier in the Module), are executable but not readable to members of the file owners (root) group (everyone with an account on the UNIX system you are on); and

(c)

Others’ permissions will determine what other users can

with

the

files

you

create.

Normally

this

will

do

be nothing,

although you can specify otherwise. the topic of permissions interests you you might return to the

If

root directory and explore

some more. Try doing

a long listing in

several of the bins and interpreting the information supplied to

you.

In other words,

spend a few moments and “get lost,” but do

report back.

(18) Additional information about bins

and modes

UNIX Programmer’s Manual. To access

is

available in the

this material enter the Shell

commands: apropos

modes

®

or

apropos

(19)

A

bins

®

Final Quick Review: Consider these questions:

What

(a)

Shell

command

will

move you

directly to the root direc-

tory? (b)

What command would you use Shell?

380

Commands &

Files

to reset

your path from the

(c)

What

three steps woula you take to reset your path by modi-

fying your .login file? ( 1 ) (

2)

(

3)

Answers: (2)

(a)

cd /

append “set path

(b) set

=

(

path

=

new path )”

(

new path (3)

)

source

(c)

(1) vi

.login

login

Commands &

Files

381

Module Twenty-Three

Form

Letters

Introduction Multiple copies of a form letter can easily be generated on UNIX. This process requires only that you learn a few additional com-

mands.

Prerequisites Before starting (1)

Use the

(2)

Use both

this

Module you should be

visual editor;

nroff

able to:

and

and -ms macro commands

to

format

text.

Objectives Upon completion

of this

multiple copies of a form

Module you should be

able to produce

letter.

Procedure When

producing form letters you create two files: the first contains the basic form letter, complete with blanks to be filled in later; the second contains the list of whatever text (names, addresses) should be inserted in the blanks of the form letter.

382

(1)

Log onto your UNIX account and when the Shell prompt presented use the visual editor to start a new file called letter.

(2)

An Arc^Request in this

new

Reading Input:

for

is

Insert the following five lines

file:

.LP Dear .rd

.PP //ow’s

The

going

command

.rd

part of

it

your

letter

contain a

will

list

stands for read, and is

to

be

lets

The next

filled in later.

of names that

will

know

nroff

file

that this

you create

be inserted where the .rd

is

located. coo

Use the

(3)

ZZ command

to store this

file

and return

to the Shell. wr

Use the

(4)

(5)

visual editor to create another

Contents of the Input

new

file

called

list.

File:

Insert the following line in this

new

file:

Helen This line

the

is

name

to be

used to

fill

in the

blank in the form

letter.

Use the

(6)

(7)

The the

Shell

ZZ command

Command

to store this

Line

to

file

and return

to the Shell.

Read Input: From the

Shell enter

command: nroff

This

command

tells

-ms

UNIX

to

letter


7

/ /

(

Changing the Generic are,

of course, endless.

some

items, center

information.

.

.

Title Page:

You

entries

The

variations to this

theme

can change the vertical spacing of

and not center others, include other

.

The commands used in this section are described in the Command Summary Section at the end of the book. In addition. Module Five offers a more thorough description of each command. The keys

to successful title

page formatting are the

\& which

allow

you to format from the top of the formatted page, and the .bp 1 which begins the next page at page one. If those two commands are included in the file, whatever you do in between is up to you. (Try not to have the called for spaces add up to more than one page.)

Special Formatting Topics

395

Hermeneutical Homemaking

B.

Fido Nerfball

University of California, Berkeley

Fred Flintstone

Bedrock School of Mining

This research was

made

from the

396

Special Formatting Topics

Oil

possible through a grant

Foundation

Using the nroff Title Page title

to

page format

in a file that

add the following

(a)

An

initializing

to

-ms

you are using the nroff uses the -ms macros, you may need

in a

your

File: If

file:

macro such

as

.LP on

a line before the

\& com-

mand. (b)

A .ND graph

No Y^ate) command command to suppress the (for

.bp

1

(If

command.)

A A

printing of today’s date as the

you want the date on pages within the body add the command .DA to your file just before the

center footer.

of the text,

following the initializing para-

Title

Page Using

the

-ms Macros

of specific -ms macros can be used in place of nroff requests to construct a title page. The command sequences placed within a file to prepare a title page will first be shown. Notations series

describing each

command

A

sample title page, formatted according to these commands, has not been included. Rather, you are encouraged to create your own.

The Input

follow.

File:

.RP .TL Hermeneutical Homemaking

.AU B. Fido Nerfball

.AI University of California, Berkeley

.AU Fred Flintstone .AI Bedrock Mining College

.AB This article offers an ethnographic look at the daily existence of the

Wilma

Flintstone

Bedrock Retirement

and her

Facility, circa

associates at

2 Million B.C.

.AE As life,

any research purporting to examine prehistoric one must first consult J960*s era American cartoons

with

....

Special Formatting Topics

397

Interpreting the Input File: The following annotation of the -ms macro commands used in the above input file explains the function of each command. Following the annotation is a list of important constraints

on the use of the commands.

COMMAND

FUNCTION

.RP

Requests a separate cover sheet (optional).

.TL

Tells

UNIX

be the

title

that the next line(s) of text will

(must appear).

Place the Title

Information Here

.AU

The name(s) of

the author(s)

the next line(s). Type the as

you would

like

follow on

names

in exactly

them presented.

Author Information Here Place the

.AI

The author’s

institution

appears

on the

next line(s). Place the Institution

Information Here

.AB

An

abstract of the paper follows until the

.AE command appears

(optional).

Place the Abstract

Text Here

.AE

Marks end of .AB is used).

Begin the Text of Your Paper

Special Formatting Topics

abstract (must appear

if

the

Notes on the -ms Title Page: The above commands follow conventions that result in different outputs:

(a)

specific

With the .RP command included in the file, the title and author's institution will appear in two places: on the title page and also on page 1 of the paper. Without the .RP command a separate

cover page

will

not be prepared.

The

title

page

material will instead appear on page one with the text immediately following. (b)

The command .RP no used

in place

of the

.RP

will

suppress

the printing of the information on page one. (c)

The abstract will appear under a centered heading Abstract when the .AB request is included. To suppress this heading use the .AB no in place of the .AB request.

(d)

The commands related to author (.AU) and institution (.AI) may be repeated if there are several authors from different institutions (as

demonstrated

in

the above example).

Creating a Table of Contents

When

creating a major paper, there are two ways to collect and enter the list of entries which become the table of contents: (a)

You may produce

a draft of the paper, identify the pages that

each major section landed on, and then enter each of the entries into a separate section of your paper or, (b)

You may itself,

ask nroff to collect the entries from within the text noting the appropriate pages.

Each of these approaches

is

explained below.

Creating a Basic Table of Contents: The -ms system of macros includes a specific command to inform the formatter that an entry is the beginning of a Table of Contents. There is another command to identify intervening entries, and another for indicating the last

entry.

macros.

An

The

on the top of the next page uses -ms explanation of each macro call follows. input

file

Special Formatting Topics

399

.

The Input .XS

File:

1

Phenomenological Issues .XA 16 You,

Me, and Phenomenology

.XA 25 Tree-Frog Consciousness

.XA 32 5 Mocha Almond Fudge .XA 40 Suicide Brings on Changes

.XA 52

0

Finale-Husserl at Play

.XE .PX Interpreting the Input File:

An

annotation of the

command

lines

included above follows:

.XS

used to identify the first Table of Contents entry. The number which Is

1

follows (here, the

number of

the page

page

(here,

number

1

the

for

1)

first

indicates topic item

Phenomenological

Issues)

Phenomenological Issues

Next

.XA 16

is

You,

topic item will follow,

number

the page

and the 16

of that item.

Me, and Phenomenology

Next

.XA 25

is

topic item will follow,

number

the page

and the 25

of that item.

Tree-Frog Consciousness

.XA 32

5

Next is

topic item will follow,

the page

number 5

Special Formatting Topics

5

number of

tells

and the 32

that item.

The

nroff to indent this item

spaces to the right.

The indentation

vvill

remain

until

you inform nroff

to

return to 0 indentation (which follows).

Mocha Almond Fudge

.XA 40

Next is

topic item will follow,

number

the page

and the 40

of that item.

Suicide Brings on Changes

.XA 52

Next

0

is

topic item will follow,

the page

number

0

number of

tells

UNIX

margin to indented position).

that item.

The

to indent this item

0 spaces to the right left

and the 52

its

(i.e.,

return the

normal,

non-

Finale-Husserl at Play



XE

Marks the Contents.

.PX

Tells

last

This

entry of the Table of

command must

appear.

nroff to print this material as a

Table of Contents formatted. This

when

the paper

command

is

must

appear.

The Formatted Table sent

to

the

When the above input file is Shell command line nroff -ms

of Contents:

formatter with

the

filename, the following results:

Table of Contents

Phenomenological Issues

1

You, Me, and Phenomenology

16

Tree-Frog Consciousness

25

Mocha Almond Fudge

32

Suicide Brings on Changes

40

Finale-Husserl

at

52

Play

Special Formatting Topics

401

Collecting Entries from within the Text: The entries for the Table of Contents do not have to appear together as a set in the file (as was the case in the previous example). Instead, they may appear within the text of your paper on the pages they refer to. UNIX can be instructed to collect the entries and assign the appropriate page numbers for your table of contents. The Table of Contents generated in this

way

will

appear identical to the one created

in

the

prior example.

An example tion of a

.

.

.

of this alternate approach would be the following por-

file.

and he spoke as

Leader of the Pack.

the

.sp .ce

Mocha Almond Fudge .XS

Mocha Almond Fudge .XE .sp

This brings us into historical realism

The .XS and .XE

and

....

are entered into the text

file

wherever sections

you want included in the contents. In this case, Mocha Almond Fudge is a section title. Right after the section title The is entered, an entry for the Table of Contents is included. .XS and .XE surrounding the second Mocha Almond Fudge in the file will cause Mocha Almond Fudge to be an entry in the Table of are located that

You can not you do not know what Contents. ting.

The formatter

will

enter a page

number

page the entry

for the entry because

will fall

on during format-

enter the appropriate page

entry after the formatting

is

number

for the

completed.

Informing the Formatter: When generating a Table of Contents using the above approach you must include a .TC command at the end of your file, so UNIX knows to collect your topics and assemble a Table of Contents. The .PX command, which is included when you enter the Table as a unit, is not employed when the formatter collects the entries.

Special Formatting Topics

Creating an Index

The procedures employed

having the formatter create a Table of Contents can be used to create an Index. The process is the same; make all entries in the file using the .XS and .XE commands. in

The .TC will have the formatter collect all the entries and prepare them as a Table of Contents. Since this is to be an Index, you will need change the name of this list to Index.

Special Formatting Topics

403

Module Twenty-Five Bibliographies and Footnotes:

The REFER Program

Introduction I don't

bibliography .

.

.

writing the paper, but / can't stand typing the

mind .

.

.

underline

this,

put

in

periods,

commas

Then there are the

does the date go before the city?

footnotes. Yuk.

the above statement reflects your attitude toward bibliographies, then the UNIX refer bibliographic formatting package is for you. If

prompts you for the necessary information, then formats and alphabetizes your bibliography while you sit back and

Refer

first

smile.

In addition,

when formatting

place footnotes at the

a paper

bottoms of pages or

at

it

will appropriately

the end of the paper,

given just part of a citation.

Prerequisites Bibliographic entries and

UNIX system knowledge. (I)

404

You should

modification

call

for

basic editing

and

Specifically:

be able to edit text using the visual editor; and

(2)

Because

Module

this

phy, you

consists largely of creating a bibliogra-

need to have available either a more books and articles or their bibliographic will

author, date, journal,

series of 10 or citations

(title,

etc.).

Objectives Upon completion (1)

Use the

of this

refer

Module you should be

able to:

package to format a bibliography, including

annotations; (2)

Have your bibliography

(5)

annotations;

(3)

Correct citation entries

(4)

Alter the prompts that refer presents to meet your

in

printed both with and without the

the bibliography;

own

needs;

and

Use

refer

formatted footnotes

to create properly

in a written

Q D

work.

Procedure

L E

The procedures

will

consist of seven sections.

The

first

section

discusses the use of the refer prompts to enter citation information into a

file

covered

prompt

named

database.

Formatting and

citations. in

section three.

field

Section two describes getting

a

copy of a

and describes how

Section six discusses

the refer system.

The

to create

(1)

how

to

to edit the

bibliography

is

your own prompt is

explained

in

list.

section

to cite references in papers using

final section

Using Prompts

how

Section four considers the entire refer

Entering bibliographies without abstracts five.

M

contains a sample bibliography.

Create a Basic Bibliography

Log onto your UNIX account. When the Shell prompt appears enter the command (Note; the ® means press the RETURN key): addbib

database

® The REFER Program

405

25

If

the refer pre-processing package

is

available

on your system the

query Instructions ?

will

Answer by

be displayed on the screen.

®

yes

(2)

The addbib database command you process and

is

addbib

is

(a)

two

in

typing:

just entered initiates the refer

parts:

the Shell

command

that tells

UNIX

enter bibliographic information using the refer (b)

database

is

be placed.

we (3)

you want package, and

that

to

which the information will While you can name the file whatever you want

the

will refer to

name it

of the

file in

as database.

presented on the screen. Go ahead and read through them, but don’t worry if everything is not clear. The instructions will be covered in some detail in the next few pages.

Instructions will

now be

through the addbib process we suggest you not enter the information from an actual reference citation, but rather make up quick answers to each query. You will have a chance to

On

this first pass

enter a real citation in a

(4)

moment.

The prompt Author should appear on name, such

as your

the screen.

Type an author’s

own, or

Sigmund Freud After you have entered the author’s name, press

®

.

normal order (i.e., don’t enter surname first). When the file is formatted your bibliographic entries will be alphabetized by the first author’s surname. The output will then be printed surname first, resulting in: Freud, Sigmund Enter the

(5)

name

406

®

Pressing

the

author’s

name.

request for

in

Title is

key

indicates

The Author

you have finished entering the prompt then disappears and the

displayed on the screen.

The REFER Program

(6)

Enter a

title

such

as:

Psychoanalysis and the Couch

® and

Press

(7)

prompt gives way

Title

to Journal.

Continue through the prompts, answering those that you want, leaving others blank until you get to Abstract. After each entry press

(8)

the

® to

move

to the next

prompt.

When

the prompt Abstract appears, start entering comments about the mythical book you are citing. Since abstracts are invariably longer than one line, refer is designed so that the key now

®

works

in the

normal fashion, opening up

not shifting to the next prompt.

comments

You

a

new

line for text

and

can enter several lines of

in the Abstract field.

How

do you

since

®

is

refer

let

acting in

know you

are finished

normal way?

its

the abstract you enter the

When

making comments, you have completed

command: CTRL-D

(While holding

down

the

CTRL

key, press the d key one time.)

The prompt Continue? should appear on

(9)

the screen.

You have

two choices: (a)

If

you are finished entering

citations

and want

to return to the

Shell type no or quit\ (b)

If

you want

new (10)

continue adding citations, you can Author prompt by pressing the key. to

with a

start

®

You have now worked through

the fundamental process of enter-

ing bibliographic information using the refer system. There are several things to keep in mind while entering citations into refer. (a)

Mistakes: Don’t worry about mistakes, as they can

easily be

edited later; (b)

Irrelevant fields

Prompt

Fields: Simply pass over (with a

which do not pertain

ignored

when

to

your

citation,

®

and they

)

those

will

be

the formatting takes place;

The REFER Program

407

(c)

dealing with multiple authors, enter which will call the name of the first individual, then press the up the Title prompt. Instead of typing the title, enter This procedure will bring tninus sign ( ) and then press can up another Author prompt. The names of several authors

Multiple Authors:

When

®

®



in this fashion.

be entered (d)

.



Titles: Titles are often too long to

Lengthy

Because of

this users will often enter

most of

fit

on one

line.

a title and, see-

near the right edge of the screen, press They then find themselves facing the next prompt entry is instead of a new line to finish entering the title. If an enter a too long for one line (such as a long title of an article)

ing that the cursor

®

is

.

backslash (\) as the last character in the line before. pressing the new line, but key. The cursor will move to the start of a (because of the backslash) that line will be considered part of

®

the previous line. (e)

Terminating a Citation: If while you are entering a citation you must quit (or you have totally messed it up) just pass until through the remaining prompt fields by pressing the you reach the Abstract: prompt. The CTRL-D will bring up the prompt: Continue? At that point you can either bail out or when you start a new cycle with a new Author prompt. Later,

®

edit the

(II)

To

learn

file,

how

you can remove any aborted

to edit, format,

and

partial citations.

print the bibliography

you will Use the

entered into your database file. to enter the information for at least four published works. Use journal articles or books, but avoid articles written by one author and located in a book edited by someone else, as we’ll

need several refer prompts

-

citations

get to that later.

Editing the File

(1)

have entered your last abstract and have been presented with the Continue? prompt, enter the command:

When you

vi

This permits visual editing of your database file. You can only enter the visual editor when addbib presents the Continue? query.

408

The REFER Program

(2)

(3>

Once you have entered

the visual editor, examine the file. It should look similar to the database file located at the end of this Module. Note that the citation information begins with %T

%A

%J

and the abstract material

etc.,

%A

The

%T

and

field.

at

the end of each citation.

characters which begin each line are the refer

codes placed in the

other data

is

by

file

Your

each Author, Title, or complete entry should look something

refer

first

to identify

like:

%A %T

Sigmund Freud Psychoanalysis and the Couch

%J The Vienna

%D %V %X

Circle

1897 2

Brief account of criteria for selection

of couch for office: not too hard, nor sleep inducing.

When

the addbib program prompts you with Author, it places the in the file, followed on the same line by whatever you type,

%A

®

you press The interactive process of incorporating the prompt with the data you enter is how each field {Title, Journal, until

Date)

is

.

created.

Because you entered vi when you were presented with the Continue? prompt, you can now visually edit database as you would any file. The visual editor may be used to correct spelling errors, modify each abstract, or delete aborted citations. Notice that there is a blank line between each full citation. The blank line is used by refer to keep all the information concerning

one

citation

Do

together.

not delete these blank

lines.

They are

essential.

When

%T)

be certain all the prompt abbreand the blank lines are still in their

first citation

(your mythical article by Freud) and

finished editing the

viations (such as

%A

or

file

proper places.

Remove make any

the

other corrections you wish.

ZZ. The

When you

are finished edit-

ZZ command

does not take you back to the Shell, but rather to the Continue? prompt in refer. At this point to continue adding reference citations, or enter no you can press ing, type

®

to return to the Shell.

The REFER Program

409

Returning to the File: When you type no in response to the Condatabase file tinue? prompt you are returned to the Shell, and the storage. What if you want is written onto the disk for permanent addbib database. to add more citations to the file? You simply type When you use addbib with an already existing file, the new citations are appended to the end of the file.

Formatting and Producing a Copy of the Bibliography addbib database you started the process of creating a file called database into which all bibliographic The database file is placed in_ your UNIX entries were made. account (just like any other file) and can be formatted and line

When you

entered the

command

printed.

(1)

A

Screen Display: To get the

file

database properly formatted and

displayed on the screen enter:

database

sortbib

(2)

Line Printed Copy: To send

page

roffbib

a formatted

|

copy of the bibliography

'

to the line printer enter:

database

sortbib

Without Annotations:

If

roffbib

Ipr 1

you want the bibliography printed out

without the annotations a -x option

is

included with the roffbib

command: sortbib

With Page

Offset: If

r,

roffbib -x

Ipr |

you want the bibliography printed with

(a

larger

left

command: sortbib

410

a

one

margin), a -rOli option (minus, upper case O, one, eye) is included with the roffbib

inch page offset

lower case

database

The REFER Program

database

roffbib

-rOli

Ipr 1

i

,

i

1

Explanation of Commands: The

command

lines just presented can

be interpreted as follows: (a)

The

sortbib, sorts the entries in the

file

database by author

(and by date); (b)

The

next sent to roffbib which converts the %A %T %J prompts into specific formatting instructions and then formats

the (c)

file is

file.

Finally,

depending upon what you specify, the

file

is

sent

either to the screen (default) or the line printer.

Use of Fields Not Included (1)

in the

The addbib program does not prompt you

Prompts

with

all

the possible

For instance, if a citation is an article in a book edited by someone else, you are not prompted for Editor?, although that prompt does exist. The following is a complete list of fields that the roffbib program recognizes: fields.

%A %B %C %D %E %G

Author’s name

book in which article is located City where published Date of publication Editor of book which contains the article being Title of

%H

Government order number Header commentary which is

%I

Publisher (Issuer;“P”

%J

Name

is

cited

printed above citation

taken by “page number’’)

of journal

%K Keywords used to locate reference %N Number of issue within the volume %0 Other information or commentary %P

%Q %R

Page number (s) Corporate or foreign author (name Report number

%S

Series

title, if

book

is

one

is

not reversed)

part of such a series

%T Title of book or article %V Volume of the periodical %X Abstract The REFER Program

41

(2)

There are three ways to include fields in your file database which are not in the prompts that refer automatically provides you: (a)

You

can place additional field identifiers and field information directly into the file using the visual editor. First type the usual vi database Shell command sequence. Next, enter the appropriate refer code (such as %E) followed by a space and the necessary information. The

Entering Additional Fields from

v/:

order that you include these fields is not important; refer will Be sure to place all information in an established order. include a blank line between citations. (b)

Entering Additional Fields Using addbib: When you have typed as Title?) all the information for one of the prompts (such key. enter a backslash as the last character. Then press the

®

I

i

For instance: Title: Psychoanalysis

Instead of a

new prompt, you

and

will

the

Couch\

®

be presented with a new

Enter the refer code and appropriate information. Then press RETURN. The next prompt will now be presented.

line.

(c)

Entering Additional Fields by Changing the Prompts'. The third way to use the other refer codes is to change the prompts

presented you to include the set you want. This approach

;

i

will

next be discussed.

(3)

have addbib provide additional prompts (such as %E for Editor of a book), or if you want to eliminate those which you do not use, you must set up your own

Changing the Prompts:

prompt

If

you wish

to

;

list.

addbib present only those prompts that you select yo\x must create a file named prompts which will include the screen prompts you want displayed along with the associated refer codes (%A %B %R %S or whatever). Each line of the prompt file must contain the

To have

following:

(a)

The prompt

(b)

A

(c)

The

itself is

positioned against the

left

single [Tab] character follows each prompt; refer

on the

412

j

code (drawn from the

line.

The REFER Program

list

above)

margin;

and is

the final entry

i

!

;

i

Each subsequent line separated by a [Tab]

will also

include a prompt and

its

refer

code,

.

Note: ITABI means Press the [TAB key. (If you do not have a [TAB key on your terminal, press CTRL-I.) With each [TAB] the cursor may or may not move, and no character will appear on the screen. Because the invisible |TAB| character can be confusing, it is possible I

to

have

on the screen

a character appear

where you

to indicate

entered each ITABI character.

From the Command Mode command (don’t forget the

of the visual editor, enter the following colon):

:set list

Your [Tab]

When

will

now

appear as the

"I character.

you want the [Tab] characters

to

no longer appear

in the ter-

minal output, enter the command: :set nolist

(4)

The prompt

file

which would result

in all fields

prompted would look

like the following display.

Named

Contents of File Author? ITabi

''Prompts'*

%A

Corporate or Foreign Author? [TAB] Article/Book Title? [Tab] %T Edited

Book

Title? |Tab|

%0

%B

Journal? |Tab| %J Edited by? |Tab| %E Title of Series? ITABI

%S

Volume? ITabi %V Number? [TAB] %N Report Number? ITABI

%R

Page(s)? [Tab] %P Publisher? [TAB] %I City? [TAF] Date? [Tab]%D

The REFER Program

413

Government Order Number Header Commentary? |TAB|

|TAB|

%G

%H

Other? [TabI %0 Keywords? |TAB| Abstract?

(5)

%K [TABl %X

established a prompt

Once you have

activated (whenever

the following Shell

you want

file

in

your account,

it

is

to enter citation information) with

Command:

addbib -p I

prompts

database

space

-p prompts included in the above command line instructs addcurrent bib to use the prompts listed in the prompts file in your

The

directory, rather than the standard set.

and print your database file, the sorting (sortbib), formatting (roffbib), and printing (Ipr) com-

When

the time

comes

to sort, format,

mands are the same as described earlier. They the method you use to create the database file.

are not affected by

Entering Bibliographies without Abstracts information without entering abstract comments. The Abstract? prompt will not be presented if you include the -a option with the addbib command:

You may want

to enter bibliographic

addbib -a space

All

prompts

will

database

I

now be used

except Abstract:.

Citing References in Papers

(1)

Incorporating Footnotes: The refer pre-processor not only creates bibliographies which can be appended to a paper, but also takes care of the

414

messy job of footnoting.

The REFER Program

For example,^ the footnote at the bottom of this page was produced by including the following lines in this file: For example, .[

Tuthill 1982 .1

the footnote at the bottom of this

You do

not have to include the entire citation

text; just

(the (2)

name

enough

to

let

refer

identify

page was

.

.

.

point in your

at this

which reference you want

of the lead author and the date

will usually

be enough

to allow refer to access the correct citation).

(3)

Obtaining Formatted Footnotes The

default option in refer is to have footnotes placed at the bottom of the page.

numbered and

Page Bottom Footnotes: When it is time to format and print a file and you want the footnotes placed at the bottom of the page, use the following Shell

command

sequence:

(4)

refer -p

Here database

database the

filename

nroff

-ms

Ipr |

®

of citations and filename is the text file that has the footnote calls embedded in the text. (The -p indicates that you are using the database in your current directory— your t^rivate database instead of the system database.) is

file



Listed Footnotes:

The

package will also place footnoted referthe end of a chapter, instead of at the bottom of

ences together at each page. The Shell prints

your paper refer -e -p

'

Bill

refer

command sequence

in this

form includes the

database

filename

Tuthill, Refer-A Bibliographic System,

fornia, 1982.

Computing

line

which formats and

-e option:

nroff

-ms

|

Ipr

®

University of California, Berkeley, Cali-

Services.

The REFER Program

415

With the wherever

-e option footnotes will not in the text

be placed on each page, but

you place the following three

lines;

.1

$LIST$ .1

(5)

Science citations such as this one numbered [Tuthill, 1982] are also possible in place of superscript footnotes. You enter the same footnote marker: Social

Bracketed Citations:

.1

partial citation .1

same manner, but use a different Shell command paper. The Shell command line which formats your

in the text in the

to

format the

paper must include the refer

-1 I

I

-p

-1

(“minus ell")

flag:

nroff

filename

database

-ms

1

Ipr

space

option the senior author’s name and publication date are bracketed at the appropriate text locations.

With the

(6)

-1

Use with Other Pre-Processors: pre-processor (perhaps

Command

tbl

If

and neqn)

you are using more than one for a paper, the correct Shell

sequence would be:

refer -p

database

filename

tbl

I

neqn

nroff 1

-ms

Modification of the Programs the bibliography produced with the refer package is useful for most paper and report writing activities. It does not, however, comply with the specific style requirements of many pub-

The format of

lications (such as the

APA

Psychological Association).

Manual published by the American may be necessary for you to modify

Style It

the refer and roffbib programs punctuate and order the elements of the bibliographic citations. Although such modifications

how

beyond the scope of this edition, the interested reader is prior page. referxtCi to the Tuthill monograph footnoted on the

are

This is an excellent source of information about the refer preprocessing package and describes how to modify these programs.

416

The REFER Program

7

A Sample The following

list

of citation information

which was used the end of this Module: database

%A %A

Bibliography

file

to

is

the contents of the

produce the bibliography located

at

Joel Kies Bill

Tuthill

%T UNIX

Text Formatting Using the -ms Macros

%I Computing Services, University of California

%C

Berkeley, California

%D 1983 %K software document preparation %X All commands and conventions

of -ms are explained for use with the Berkeley system, including table of contents and other fancy features.

%A

Bill

Tuthill

%T

Refer — A Bibliographic System %I University of California

%C

Berkeley, California

%D 1982 %0 Computing Services %X The most complete source refer program.

%A %A %T

A

must

W. Kerninghan Dennis M. Ritchie The C Programming Language Brian

%I Prentice-Hall %C Englewood Cliffs,

%D 1978 %K software %X This the is

%T %I

New

Jersey

handbook for programmers the C language. The rules of the classic

who work in game are carefully

%A

if

of information about the you intend to use refer extensively.

explained.

Joseph F. Ossanna Nroff/Troff User’s Manual Bell Laboratories

%C

Murray

%D

1976

Hill,

New

Jersey

The REFER Program

4

1

%K %X

software document preparation All the specifics of nroff and troff are included

in careful detail, including options,

%A %A %T

Neil

arguments

etc.

Postman

Charles Weingartner Teaching as a Subversive Activity

%I Dell Publishing Company %C New York

%D 1969 %X The classic if

book

for

assisting people to learn to think Heady with new

The bibliography on file is

anyone interested

skills,

is

of interest.

od a

Rhett decider to

the next page results

in teaching,

when

the above database

sent to the sorter and formatter with the following

line:

sortbib

418

table...

The REFER Program

database

roffbib \

Ipr |

command

BIBLIOGRAPHY

Kerninghan, Brian W. and Dennis M. Ritchie, The

Englewood

Prentice-Hall,

This

the

is

language.

classic

The

Cliffs,

Programming Language,

New

Jersey, 1978.

for

programmers who work

handbook

rules of the

C

game

in

Bill Tuthill,

C

are carefully explained.

UNIX

Text Formatting Using the -ms Macros, puting Services, University of California, Berkeley, California, 1983.

Kies, Joel and

the

Com-

of -ms are explained for use with the Berkeley system, including table of contents and other fancy features.

commands and conventions

All

Ossanna, Joseph

New

F., NrofflTrojf User’s

Manual,

Bell Laboratories,

Murray

Hill,

Jersey, 1976.

All the specifics of nroff

and

troff are

included

in careful detail,

including

options, arguments etc.

Postman, Neil and Charles Weingartner, Teaching as a Subversive Publishing Company, New York, 1969.

The

classic

book

learn to think Tuthill,

Bill,

is

for

anyone interested

in teaching, if assisting

people to

of interest.

Computing

Services.

The most complete source of information about if

Dell

Refer-A Bibliographic System, University of California, Berkeley,

California, 1982.

must

Activity,

you intend

the refer program.

A

to use refer extensively.

The REFER Program

419

Module Twenty-Six Setting Tables:

A

Busboy’s Nightmare

The TBL Pre-Processor

Introduction Text processing often requires that information be presented in columns or tables. Merely the thought of having to tediously count the needed spaces, divide by 2, center, backspace, etc., is enough to convince all but the most determined writer to seek

some

alternate

contains

tbl to

way

to present the information.

Fortunately UNIX

help with this task.

Prerequisites In writing this section,

that

(1)

Use the

(2)

Use the basic nroff commands words, and skip lines; and

(3)

Use

visual editor to

Shell

commands

line printer.

420

we assume

to

you are able

add and change text

format a

to

file

center

to:

in a file;

lines,

and send that

underline

file

to the

Objectives Upon completion (1)

Module you should be

able to:

Properly format multicolumn tables which contain numbers,

words or (2)

of this

text entries.

Systematically

troubleshoot

when

do

tables

not

work

as

planned.

Procedure The following introduction to table formatting starts with a two column format and, by adding commands, demonstrates some of the more complex forms which are possible. These procedure steps are grouped

The first simple two column

into four sections.

section presents instructions for formatting a

Section two describes how to send a file containing a table to the formatter. The third section builds upon the simple table by adding more columns and different kinds of data. The last section table.

coo

includes examples of boxes and the use of different sizes of type. mr

A An Example

Table for Two, Please

The following two column display was proUNIX tbi program. This table will serve as the the more complex tables to be presented in later

Table:

duced using the starting point for

sections of this Module.

produce

An

explanation of the

commands used

to

this table follows.

The TBL Program

421

Table

Equipment

Cost

Hammer Radial Arm Saw

14.95

389.50 39.50 69.95

Tool Box Electric

A

Sander

Work Bench

179.

Gasoline Chain

Saw

166.80

How

Tables are Formatted: Tables are formatted by giving specific instructions as to how each row and column are to be presented. Columns are the vertical, up and down units in a table; rows the horizontal, across units.

For example,

in Table

Column One

Cost

Hammer Radial Arm Saw

14.95

389.50 39.50 69.95

Tool Box

Sander

Work Bench Gasoline Chain

A

row

is

the two columns are:

Column Two

Equipment

Electric

A

179.

Saw

166.80

‘‘sliced” horizontally.

The

Equipment and the second row

The TBL Program

row of Table A

Cost

is:

Hammer

422

first

14.95

is:

and nroff

be able to format the display of a table you must provide specific instructions as well as the data to be entered. For all tables you must indicate:

For

tbl

(a)

The number of columns of information (in Table A there are two columns);

the table will contain

(b)

How

to

to

the information in each

column

is

whether each entry should be centered against a

left

or right

numbers, adjusted (c)

The

actual

column margin,

be displayed

in the

or,

column, pushed

the information

if

relative to a decimal point);

information

(data)

you

(i.e.,

want

is

and

placed

in

each

column.

Using the |TAB| Key: The directions were entered as follows:

for

Table

A

using the [TAB

.TS c c 1

n.

Equipment

Cost

.sp

14.95 Hammer Radial Arm Saw

Tool Box

389.50

39.50

69.95 Sander 179. Work Bench Gasoline Chain Saw .TE Electric

What

is

tricky with this

166.80

example

is

that in looking at the

above

you would never know the |TAB| key was used to separate the entries for each row into two columns. For instance, there is a TAB! entered between Hammer and 14.95 in the first row of data. There usually is no apparent symbol. (A |TAB| character tends to be quite secretive.) This is due in part to the fact that the [TAB] key does not adjust your screen display in the same way as the [TAB] key on a typewriter affects the typed page. display

Defining a [TAB] Character: Because the ITABI key can be very confusing to use when setting tables (and is almost impossible to demonstrate here) we recommend defining some other character

The TBL Program

423

which

will

show up on

following table instructions

above, only the plus sign In this

ter.

ded

(

+

)

is

defined as the separation charac-

example the separation character can be seen embed-

in the instructions.

.TS

Instructions for Table

(+)

tab

column entries. The produce the exact same Table A seen

the screen to separate

A Using

the Plus Sign

;

c c 1

n.

Equipment + Cost .sp

Hammer + 14.95 Radial Arm Saw+389.50 Tool Box + 39.50 Electric

Sander -1-69.95

Work Bench

-I-

179.

Gasoline Chain

Saw

-I-

166.80

.TE

(1)

Log onto your UNIX account. Select one of your practice files (such as the musty first file) to use with these exercises. As you read through the following examples, enter the format instructions at

some

interesting point in your

file.

you should follow the format instructions that we present. You could easily change the data to whatever content amuses you, however. In entering the tables into your

file,

Explanation of Instructions for Table This section

will

A

describe the function of each of the above Table

Format instructions used in setting Table A, beginning with the first command line. As you read the following, examine the effect of each command on the formatted Table A. .TS

Indicates that a Table Starts with the next line of text.

It is

one-way command and is paired with the Table Tnd (.TE) command (which must be the last command in the

a

424

The TBL Program

table).

The

entire unit,

from .TS

to

a separate file or placed in a text

where you want the formatted tab( + );Informs the

sign character

(

file at

+

)

in

the exact location

table to appear.

program formatter

tbl

.TE, can be located

that

you

will

use a plus

column

instead of a [TAB] to separate the

program will look for [Tab] characters. The semicolon (;) at the end of this line indicates that the options are concluded and that Without

entries in the input line.

the

actual

column layout

semicolon must appear c c

Instructs

the

first

(a)

(c)

instructions

will

follow.

The

any options are selected.

concerning how you want data entries placed row of the table, namely that: tbl

there are two symbols, therefore the table

matted (b)

if

this line the

in

the

first

(c)

and,

the

centered

be for-

to

two columns,

entry for the

first

column should be

centered

column should

also be

entry for the second

first

is

in

(c).

(These entries

will in fact

be the column

heads.) 1

n.

how

the data in the second row

be formatted. The first entry is to be placed against the left (1) margin of the first column. The second entry is to be one number (n) arranged in the second column so the decimal points are aligned. The period must be included at the end of whichever is the last line of table formatting commands. The period indicates that the formatting instructions are Indicates

is

to

over and that the data to be included in the table will start on the next line. Without the period, the table is not set, and no dinner

most Data

The

will

be served.

common

Failure to include the period

is

the

table formatting error.

actual table information

is

then entered, line by

with a plus sign (-f) separating the column entries. data entry for the first row of the table is:

line,

The

Equipment + Cost

+

move on to the next column. Thus, in the formatted output. Equipment will be in the first column, and Cost in the second.

The formatter reads

the

sign as

The TBL Program

425

When

the

®

RETURN

of the table has been entered the pressed. The next line is then typed,

line

first

key

is

followed by the next, until

all

the data has been entered.

Each row is a separate line in your lines would look like the following:

file.

These remaining

Hammer + 14.95 Radial Arm Saw + 389.50 Tool Box + 39.50 Electric

Sander + 69.95

Work Bench + 179. Gasoline Chain Saw + 166.80

When

.TE

the entire table has been entered you

the conclusion with the

must

indicate

.TE command.

Relationship Between Instruction Line and Data Line: Look back The first line of the format Table A. at the instructions for instructions (c c) and the first line of the data (Equipment + Cost) are both needed in order to format the first row of the table. The formatting instruction consists of two characters, c c which indicates that there will be ter

is

two columns. The

fact that the first charac-

a c indicates that the first piece of information

is

to be cen-

column. The scond c indicates that the data for the second column should also be centered. The first line of data provides the two pieces of information needed for the first row. They are separated by a plus sign ( + ). tered in the

first

The second

line

of instructions and the second line of data—



both the data and format instructions for the second row in the formatted table. In this row, the first entry for the first column is to be formatted left, and the second column entry lined up by its decimal point. The last instruction line (1 n.) is then used with all remaining data lines to format all remaining rows in the table. together

Having a Table Formatted

A

General Process Comment: The formatting commands and the table information are both entered into a file just like all other content and formatting commands. The only difference is that if a file

426

The TBL Program

contains a table, it

is

it

must

first

be sent to the

sent to the regular nroff (or nroff -ms,

tbl if

pre-formatter before

you use the -ms mac-

ros) formatter. (1)

A

copy of the formatted table can be displayed on your terminal screen by entering the Shell command line: (2) tbl

(3)

To produce mand line:

filename

tbl

page

|

®

a line printed copy of the table, enter the Shell

filename

tbl

The

nroff \

pre-formatter

table instructions

is

nroff |

Ipr |

a pre-processing

com-

®

program that takes your

and converts them into commands that the nroff

format program can understand. Once tbl is finished, the output must be sent (with the pipe command) to nroff (or nroff -ms) |

where the

table

is

finally

formatted.

Setting

Would

A

Amy

Different Table

Vanderbilt Approve?

There are innumerable variations to the ways tables may be set. A table can be centered on the page or spread out to full page width; entries can be placed differently in the layout; several columns can be created; entries can span columns; and text can be included in addition to words or numbers. Each of these will be demonstrated by making changes in the command structure of the sample Table A you have already examined.

(1)

Locating a Table on a Page: Table A was printed against the margin of the page. Additional choices exist, however.

The TBL Program

left

427

following set of instructions produces a formatted

The

which

is

centered

on the page:

Instructions for Table

.TS tab

(

+

)

Table B,

B

center;

c c 1

n.

Equipment + Cost .sp

Hammer + 14.95 Radial Arm Saw + 389.50 Tool Box+39.50 Electric

Sander + 69.95

Work Bench + 179. Gasoline Chain Saw + 166.80 .TE

The above

instructions result in the following centered Table B:

Equipment

Cost

Hammer Radial Arm Saw

14.95

389.50 39.50 69.95

Tool Box Electric

Sander

Work Bench Gasoline Chain

179.

Saw

166.80

Notice that the only difference between the instructions for Table

A and

Table

the tab

(

+

)

B

is

the inclusion of the

word

between Without the

center inserted

and the semicolon on the second

line.

center instruction, tbl defaults to placing the table against the left

margin, as

(2)

The

did in Table A.

expanded to the with the word expand.

table can be

ing center

Try making.

428

it

first

full

width of the page by replac-

centering and then expanding the table you have been

The TBL Program

(3)

Number Data Placement:

Center, Right, Left, and

In the preced-

examples the column headings were centered over the column, the items (first column) were placed against the left margin, and prices (second column) were lined up according to the decimal ing

points.

We

format the table with both the headings and the content pushed to the right margins. This is effected with the following set of formatting instructions for can just as easily instruct

Table

C

tbl to

:

.TS

Instructions for Table

C

tab( + ) center; r r r r.

Equipment +Cost .sp

Hammer -1-14.95 Radial Arm Saw-f-389.50 Tool Box -1-39.50

Sander -1-69.95 Work Bench -1-179. Gasoline Chain Saw -1-166.80 .TE Electric

The formatted and centered

Table

C

appears as follows:

Equipment

Cost

Hammer Arm Saw

14.95

Radial

389.50 39.50 69.95

Tool Box

Sander Work Bench Gasoline Chain Saw Electric

(4)

The only

B

differences between

179.

166.80

the instructions for

Table

C

and

which appear in Table C, replacing the c c and 1 n formatting instructions. Each set of instructions contains 2 characters, corresponding to the 2 Table

are the two

r

r

lines

(lines

3

and

4)

The TBL Program

429

columns

in

each

table.

The

r

calls

for the

column entry

placed against the light edge, while c formats to the center, the

left

1

to be

against

edge, and n adjusts numbers according to decimal points in

the respective columns.

r, 1,

(5)

Try various combinations of the column entry instructions n, and c.

Headings: Often

it

is

useful to have a table entry act as a

title

or as

This requires that the title be written {spanned) across more than one column. Try the following instructions for a sub-heading.

Table

D

:

.TS

Instructions for Table

tab( + ) center; c s c s c c 1

n.

Table

D

.sp 2

House Building Equipment .sp

Equipments- Cost .sp

Hammer -b 14.95 Radial Arm Saw-f 389.50 Tool Box4-39.50 Electric

Sander +69.95

Work Bench + 179. Gasoline Chain Saw + 166.80 .TE

430

The TBL Program

D

The

above

Table

D

produced

instructions

the

headings

following

in

\

Table

D

House Building Equipment Equipment

Cost

Hammer Radial Arm Saw

14.95

389.50 39.50 69.95

Tool Box

Sander Work Bench Gasoline Chain Saw Electric

The

179.

166.80

command

entered for rows one and two means center and span. Thus, the entry is spanned across both columns of the table. c s

Table Entry

The options

for specifying

Option

Command Summary

placement of table entries

are:

Function

r

Places the entries against the right edge of the column.

1

Places the entries against the

c

Places the entries in the center of the column,

n

Adjusts

s

Spans the previous entry across

all

left

edge of the column,

entries so that the decimal points are lined up. this

column.

The TBL Program

431

(6)

Try using each of the Table Entry Commands to vary the placement of the headings and data in your table. When finished go ahead and eat lunch — you deserve to eat from a table (considering how many you have set). There is more to come. .

.

.

Waiter, a Table for Four, Please

(7)

tables are created by: (1) changing the instructions to indicate the number of desired columns to be used as well as how

Multicolumn

you want the information placed needed table data.

in

them, and

(2)

including the \

Table

E

demonstrates

formatted Table

how

E follows

to create a four

tab(H-) center;

csss csss c c c c

n 1 r. Table E 1

.sp 2

House Building Equipment For Sale .sp

Equipment + Cost + Color -h Condition .sp

Hammer4-14.95 + brown + Beat up Radial Arm Saw + 389.50 + blue + New Tool Box + 39.50 +green 4- Fair Electric Sander + 69.95 + mauve + Untouched

Work Bench + 179. +grey + Bad news Gasoline Chain Saw + 166.80 + red + Trouble .TE

The TBL Program

table.

on the next page.

Instructions for Table

.TS

432

columned

E

The

Table E

House Building Equipment For Sale Equipment

Cost

Hammer Radial Arm Saw Sander Work Bench Gasoline Chain Saw Electric

(a)

The

The

Beat up

389.50 39.50 69.95

blue

New

green

Fair

179.

grey

166.80

red

mauve

Untouched Bad news Trouble

Instructions Resulted in Table

E

each instruction line has four characters means that there will be four columns;

in

fact that

csss) (b)

Condition

brown

14.95

Tool Box

How

Color

first

line

of instructions

should be formatted:

csss

tells

how

means

the

first

it

(such as

row of the

table

center the first (and only) data

entry across all four columns;

The

corresponds with the first line of data: Table E. Therefore, Table E is centered across all four columns. (c)

first

instruction

The second

instruction line

spanned across

all

(csss)

one entry

be four columns: House Building Equipment For also calls for

to

Sale. (d)

The

third instruction (c c c c) calls for centering of information in

each of four columns. Therefore in the third data line there must be four entries separated by the plus + character: Equipment, Cost, Color, and Condition; and (e)

The fourth

line

of instructions

(1

n

1

r.)

tells

the computer

how

format each of the remaining rows: \eft, number, \eft and Tight. Because all of the remaining rows of data will follow this format, the instruction line does not have to be repeated. The period (.) must follow the last character in this line. to

The TBL Program

433

Changing

(8)

In constructing a table

the Setting in

it

may be

Mid-Meal

necessary to change the format

Perhaps a sub-heading or related but different data must be entered. For instance, assume the house building equipment in our example is available at two

after

some of

different times.

the data are entered.

The following

table could

convey

Instructions for Table

.TS tab(-l“) center;

csss csss c c c c

n 1 r. Table F 1

.sp 2

House Building Equipment For Sale .sp

Equipment + Cost "H Color + Condition .sp

Hammer + 14.95-Fbrown + Beat up Radial Arm Saw+389.50+blue + New Tool Box + 39.50 -hgreen-l- Fair .T&

csss 1

n

1

r.

.sp

Available After June 30 .sp

Sander + 69.95 -F mauve -F Untouched Work Bench + 179.+grey 4-Bad news Gasoline Chain Saw + 166.804-red + Trouble Truck -F 1200 -F white + 200K miles .TE Electric

434

that information.

The TBL Program

F

The resulting table— with format middle— follows:

instructions

changed

in

the

Table F

House Building Equipment For Sale Equipment

Cost

Hammer Radial Arm Saw

Color

14.95

389.50 39.50

Tool Box

Condition

brown

Beat up

blue

New

green

Fair

Available After June 30

Sander Work Bench Gasoline Chain Saw Truck

69.95

Electric

The

initial

Table E.

The fourth

placed (1 n

1

r).

.T&

entered.

more

red

Trouble 200K miles

white

for

F

Table

how

Untouched Bad news

are

the

same

as

for

the table data should be

All of the data lines will be formatted following

.T& command

result

is

that

is

commands and you can format

the format of a table, enter

enter

166.80

1200

additional format

The

grey

line specifies

that specification, until the

the

179.

commands

format

mauve

more

encountered.

then

new

Following

data can be

a table, enter data, alter

data, alter the format,

and again

data.

Try creating your own table

in

which the format changes dur-

ing mid-course.

Using Text for Entries

(9)

numbers and

few words, tables can have entries which are entire blocks of text. The following example demonstrates the use of the blocked text option of the table program. In addition to

a

The TBL Program

435

Instructions for Table

.TS tab

(

+

G

center;

)

c s c s c c 1

lw(3i).

Table

G

.sp 2

Housebuilding Equipment

for Sale

.sp

Equipment -f Comments .sp

Hammer + T{ This

a standard 20 oz. nail

is

whomper, well used

in

construction of two houses. T)

Radial Arm Saw-I-T{ An extremely useful tool, can change blade direction for wide variety of cutting angles. T)

Tool Box H-T{

Standard carpenter’s multi level carry everything, find nothing tool box. T) Electric

Sander+T{

Vibrate your eyes out, ears ordinary sander.

fill

your lungs with dust, blast your

T)

Work Bench + T{ Wood,

3

ft

by 6

ft

8 drawer, one vise butcher shop.

T)

Gasoline Chain SawH-T{ Been through two forest fires and four friends’ fireplace supplies. T)

.TE

The

table generated with these

the next page.

436

The TBL Program

format instructions

is

presented on

Table

G

Housebuilding Equipment for Sale

Equipment

Comments

Hammer Radial

This

a standard 20 oz. nail

is

whomper,

well used in construction of two houses. An extremely useful tool, can change blade direction for wide variety of cutting

Arm Saw

angles.

Tool Box Electric

Standard

carpenter’s multi level everything, find nothing tool box.

Sander

carry

Vibrate your eyes out, fill your lungs with dust, blast your ears ordinary sander.

Work Bench

Wood, 3

Gasoline Chain

butcher shop. Been through two forest

Saw

by 6

ft

ft

8 drawer,

fires

one vise

and four

friends’ fireplace supplies.

When

using text blocks in a table you need to

remember four

things: (a)

The width of of the

a text block

table.

number can be brushes.

You

use

The T{

In Table

is

the

stated in the instruction section

G

w(#) where

notation

in inches, picas, points,

column

will

the

#

centimeters, or tooth-

this instruction line reads

cating that the second (b)

is

have a

vf idth

1

lw(3i)., indi-

of 3 inches.

placed after the [TABI character and indicates that a

text block will follow; (c)

The

text begins

(d)

The

T)

is

on the next

line;

and

placed on the next line after the end the text block.

'^Spanning'' Information Across Row^s Tables are seldom as neat and tidy as those we have presented so far. The following example demonstrates how to center an entry across two rows.

The TBL Program

437

.

Instructions for Table

.TS

H

tab (H-) center;

csss csss c c c c

n c n. Table H 1

.sp

Students in Braucher Elementary School .sp

Teacher 4- Grade + Gender + Number McKinney + 64- Boys + 13

V+\''+Girls + 18 Forbes + 7 + Boys + 16

V+V+Girls + 15 Place + 8 + Boys + 17 V+V+Girls + 15 .TE

The above commands produce

the following Table H:

Table

H

Students in Braucher Elementary School

Teacher

Grade

McKinney

6

Forbes

7

Place

8

Note the placement of the

Gender Boys

Number

Girls

Boys

18 16

Girls

15

Boys

17

Girls

15

commands

13

in the data field.

They

not to place any new element in that position, but instead to (2) pull down the information from the row above so that it is horizontally centered across both rows. Thus, instruct the formatter

McKinney and rows {Boys and

438

6

(1)

appear appropriately

Girls )

The TBL Program

at

the middle of the two

Using Troff to Format Tables

You

can format even fancier tables

typesetter.

if

you have access

to a photo-

Consider the following several examples.

Allbox: The allbox in the options line of the instructions results the centered Table I with each data item individually boxed:

.TS tab

Instructions for Table (

+

)

in

I

allbox center;

c c 1

n.

Equipment + Cost .sp

Hammer + 14.95 Radial Arm Saw+389.50 Tool Boxf39.50

Sander + 69.95 Work Bench + 179. Gasoline Chain Saw + 166.80 .TE Electric

Table

I

Equipment

Cost

Hammer Radial Arm Saw Tool Box Electric

389.50 39.50

Sander

69.95

Work Bench Gasoline Chain

14.95

179.

Saw

166.80

Box: The allbox option can be replaced wi^h box, which will produce a single box around the entire table. This is demonstrated in Table J, presented on the following page. The TBL Program

439

Instructions for Table J

.TS tab

(“I")

box center;

c c 1

n.

Equipment + Cost .sp

Hammer + 14.95 Radial Arm Saw + 389.50 Tool Box+39.50 Electric

Sander + 69.95

Work Bench + 179. Gasoline Chain Saw + 166.80 .TE

The box in the options lowing boxed display.

line of the instructions results in the fol-

Table J

Equipment

Cost

Hammer Radial Arm Saw Tool Box Electric

Sander

Work Bench Gasoline Chain

14.95

389.50 39.50 69.95 179.

Saw

166.80

Vertical and Horizontal Line Placement:

It

is

also

possible to

where vertical and horizontal lines should be included inside a basic box table. This is demonstrated in the following Table K, which appears on the next page. The instructions necessary to prospecify

duce the table are presented following.

440

The TBL Program

first,

with the finished formatted table

.TS

Instructions for Table

+ csss csss tab

(

)

K

center box;

c c c c

n c n. Table K 1

.sp

Students in Braucher Elementary School .sp

T eacher -h Grade -b Gender 4- Number Ca vette + 64- Boys 4-13 \^4-\^4-_4-_ \^4-\^ 4-Girls 4-18

Forbes 4-74- Boys 4-16 \^-l-\^-l-_4-_

\^-l-\^-hGirls-hl5 Koettel 4-84- Boys 4-17

V-hV-h_-i-_ -1-Girls 4- 15

.TE

Table

K

Students in Braucher Elementary School

Teacher

Grade

Cavette

U

Forbes

Koettel

7

Gender

Number

Boys

13

Girls

18

Boys

16

Girls

15

Boys

17

Girls

15

8

The TBL Program

The

pipe

placed within the format instructions calls for a single

1

vertical line, while a

double pipe

produces a double

||

line.

The

underscore _ in the data requests a single horizontal line (note that this underscore is not a minus sign, hyphen, or dash)', and an equal sign = results in a double horizontal line.

Changing Type Characteristics allows you to change font types or point size of your printed output. Font type can be affected with the follow-

The phototypesetter

ing line in your format instructions:

cfB

The cfB

s

s

s

s

reads center and span the data across all change font to boldface. Point size can be

s instruction

s

four columns, and affected with the following line in your format instructions:

cpl4

The cpl4

s

s

s

s

s

s instruction reads center

and span the data across

all

four columns, and change ^oint size to 14.

both font type and point size can be affected with the lowing line in your format instructions: Finally,

cfBpl4

The cfBpl4

s

s

s instruction

s

s

fol-

s

reads center and span the data across

four columns, change font type to boldface,, and change ^oint size to 14. The effects of changing font type and point size are demonstrated in Table L which follows on the next page.

all

,

Reference Material: With the material contained in this Module your table settings should please even the most demanding diner. Should you require additional help— and good help is so hard to find these days— you might look at a pamphlet available from Bell Labs entitled TbI—A Program to Format Tables.

442

The TBL Program

.TS tab

Instructions for Table

+

(

)

L

center box;

cfBplZ s s s cpl6 s s s cfBplZ cplZ cplZ cplZ n c n. Table L 1

II

I

.sp

Students in Pat Lloyd Elementary School .sp

T eacher + Grade -b Gender + Number McKinney + 6 + Boys + 13

\^+\^+_+_ \^+\''+Girls + 18

Calhoun + 7 + Boys + 16

\''+\^+_+_ \^+\^+Girls + 15 Place + 8 + Boys + 17

\^+\^+_+_ \''+\^+Girls + 15

.TE

Table L

Students in Pat Lloyd Elementary School Teacher

Grade

McKinney

6

Calhoun Place

Gender

Number

Boys

13

Girls

18

Boys

16

Girls

15

Boys

17

Girls

15

7

8

The TBL Program

443

Table Formatting Shell

Summary

Commands

Command tbl

nrofF

[filel

Function

-ms

Sends

to

filel

results

be

be

will

formatted;

displayed

on

screen.

tbl

[filel

nroff

-ms

|

Ipr

Sends

filel

sends

the

to

be formatted and

formatted version to

the line printer. tbl

[filel

troff

-ms

—Q

Sends

filel

to

be formatted and

sends the formatted version

to

the phototypesetter.

Formatting

Commands

.TS

Notifies nroff that a table follows.

.TE

Notifies nroff to return to

formatting.

Table

Commands

1

left justify

c

center

r

right justify

n

number

s

span

The TBL Program

normal

Module Twenty-Seven Equalizing Equations

The EQN Pre-Processor

Introduction Mathematical equations employing symbols and characters foreign to typewriters are usually hand-drawn for inclusion in papers and reports. With the text preformatters eqn and neqn you can have UNIX format extremely complex equations— regardless of whether they make any sense— allowing you to include equations in your written

work or

reports. wrcDO

Prerequisites Before working on this Module, you should be able (1)

Employ

(2)

Use

the visual editor to add text to a

nroff,

troff,

file;

and -ms macro commands

27

to:

0

and to

have

files for-

matted and printed.

Objectives After completion of this (1)

Module you should be

able to:

Write instructions necessary to properly format a wide variety of mathematical equations;

445

Have equations numbered, centered

(2)

as figures, or included in

the body of text; and

Make

use of eqn reference materials to solve cated equation formatting problems.

(3)

more compli-

Procedure format mathematical equations including a very wide variety of mathematical symbols— providing you include the proper instructions. Although this process is designed primarily for use

UNIX

will

with

more

versatile output devices

(such as a phototypesetter or

with graphics capabilities), basic equations .employing only keyboard characters can be displayed on a terminal of modest intelligence or a standard line printer.

terminals

This Module is in two sections. In the first, simple equations that can be displayed on most terminals will be employed to illustrate the general formatting processes. The second section will demonstrate several more complex examples which you will probably not be able to view on your terminal. Normally you will need to use a typesetter or similar device

(See

Module Nineteen:

to

properly format these equations.

Phototypesetting with Troff for

more

infor-

mation about typesetting.)

Single Line Equations

(1)

(2)

Basic Formatting Steps: Log onto your UNIX account. When the Shell prompt is presented start a new file called eqn, example. Enter the following two lines

in the file:

.PP This

Then

file is

an example

for equations.

enter the following three lines:

.EQ 6 times 5

.EN

446

file

eqn

=

30

The .EQ

is

a one-way

command

that tells the pre-formatter an

The conclusion of the equation specifications is marked with a .EN instruction. As with all formatting commands, the .EQ and .EN must be on lines by themselves and must start with periods. Whatever is typed on

equation

begin with the next

between the two commands

lines

(3)

will

line.

will

be formatted as an equation.

Formatting Files that Include Equations: To have the terminal display your eqn. example file with its formatted equation, you should return to the Shell and enter the following:

neqn

The

\

eg n.exa triple]

nroff \

-ms

|

resulting equation should appear centered

®

page

on your screen

as:

6x5=30 (4)

The neqn program formatting package. specific

commands

is

a preformatter for nroff with the It

-ms macro

translates your equation instructions into

that can be formatted by nroff.

Thus the

file

be sent to neqn and then piped to nroff. (In the above example, the formatters replace the word times with a multiplication sign, and then properly center and space the equation.)

must

first

designed to do the best possible job of formatting equations for terminals and line printers, given the constraints of available characters and full line spacing on most

The neqn preformatting package

is

terminals.

could just type 6x5 = 30 without ever invoking the preformatter,” you say. True, but the keyboard characters and spacing capabilities of most terminals would make the following equation a ‘‘But

I

tad difficult:

t

=

1.96

Although terminal display of such equations is seldom possible, you will soon be able to enter commands to have UNIX produce monsters like this one on a typesetter.

eqn

447

When

be produced on a typesetter (and not a line printer or your terminal screen) you enter the identical formatting commands in your text, but a different preformatter is employed. The troff preformatter is named eqn, while neqn is the nroff preformatter. The eqn preformatter interprets the same formatting commands, but in a way to take advantage of the wide the final output

is

to

range of symbols and spacing capabilities provided by a typesetting

machine.

When

neqn interprets the formatting commands, it uses the keyboard symbols to approximate as well as possible the mathematical symbols requested. As could be expected, the neqn interpretation of the formatting nals

(5)

is

commands

as printed

on

line printers

and termi-

often less than satisfactory.

you employ the -ms macro package with either nroff or troff, equations are centered on a page unless you instruct otherwise. To have the equation placed next to the left margin of the text, replace the .EQ with .EQ L (as in the fol-

Placement on the Page:

If

lowing instructions):

.EQ L 5 times 6

=

30

.EN The

resulting equation appears at the left margin:

5x6=30

(6)

Equations can be indented from the left margin much like paragraphs. To have the equation indented, use the starting command .EQ I (I Indent) followed by the content of the equation. For example:

.EQ

I

5 times 6

=

30

.EN The product, upon formatting,

5x6=30

448

eqn

is

in

an indented equation:

(7)

Identification: Equations can also be

numbered

or labeled.

Con-

sider:

.EQ (Equation-A-) 5 times 6

=

30

.EN The above

set of instructions

produces the following labeled equa-

tion:

5x6=30

(8)

(Equation-A-)

no spaces in the label. The formatter is programmed to accept only one “word.” If you do want a space character in a label (such as “Equation A”) you must specify the space with a backslash and zero \0 such as:

Note

that there are

.EQ (Equation\0A) 5 times 6

=

30

.EN The equation

with a space in the label appears:

5x6=30

(9)

(Equation A)

Inclusion within a Line of Text: The process of placing equations within a line of text text is slightly more complicated. First, the formatter must be informed of the symbol you are using in the text to indicate where an equation is to be included. Then it must

be given equation formatting instructions. signs can be used as an equation delimiter lines are entered in a file:

For instance, dollar if

the following three

.EQ delim $$

.EN Once

the formatter reads to the above lines

equation instructions

all

text located

it

will

then treat as

between two dollar

signs,

eqn

even

449

they are in the middle of a line. This process makes it possible to place equations in the middle of a line of text. The following if

line in a file:

Simple equations such as $5 times appear formatted

will

if

you need

=

30 $ can be included.

as:

5x6=30

Simple equations such as

What

6

can be included.

normal purposes? To do so you enter:

to use a $ for

have the delimiter turned

off.

its

You must

.EQ delim

off

.EN

Advanced Equations Using Mathematical Symbols The

following examples will not look very satisfactory on most ter-

minals.

the eqn

You should

enter

filename

you are not familiar with the

Nineteen: Phototypesetting with

to

troff \

then send them to -ms for formatting and file,

do

this will be:

-ms

troff text

processor see

Module

Troff.

Available Symbols: Table 1 presents a list of symbols available on eqn. They are approximated as closely as possible by neqn for line printers

(2)

your

The usual command eqn

(1)

into

preformatter, and then to troff

phototypesetting.

If

them

and terminals.

Marks: Quite often an equation requires that a vector, bar, underline, and other diacritical mark be placed on top or below letters or symbols. The commands which create Use

of the Diacritical

these effects are bar, dot, dotdot, dyad, hat, tilde, vec, and under.

The

450

selected

eqn

command,

if

placed after any letter, symbol, or

word

Table

1

Symbols Available with Mathematical Symbols Input

eqn

Greek Letters

Results

Input

Results

DELTA

A



GAMMA

r

grad

V V

LAMBDA OMEGA

half

'/2

PHI

n o

inf

oo

PI

n

int

I

PSI

approx cdot del

n

inter

SIGMA THETA

nothing partial

prime prod

I

UPSILON

d f

A

0 Y

XI

Tl

alpha

a

sqrt

V

beta

/3

sum

I

chi

X

times

X

delta

8

union

u

epsilon

e

eta

V

gamma

y

iota

L

« »

kappa

K

lambda

\

±

nu

V

omega

OJ

omicron

o

pi

7T



->

+ = —— -

mu

1

>

• • •

1

= >







>

rho sigma

P

X dotdot

X X X x

tau

T

X hat

A JC

theta

9

upsilon

V

X bar X

under

X dot

X tilde

X vec X dyad

X X X

psi

a

xi

zeta

c

eqn

451

the formatting instructions, will position the mark appropriately equation. in the output. This is demonstrated in the next

in

.EQ X hat

Y

+

dyad



OMEGA

under times

+

word vec

A

tilde

+

y dotdot

.EN The above

material produces symbols with diacritical marks:

X

(3)

T T—

_n X

word

+ A +y

A

wide range of equations is possible using the mathematical symbols, Greek letters, and words. Consider:

Greek Letters:

.EQ union 24 apples

+

dough

+

spices

->

4 PI

.EN The above instructions— when properly baked by

the formatter-

produce:

IJ 24apples^dough-\-spices^4U

Of course,

a corollary

is:

*

.EQ int 4

PI

+

4 people

-> approx

4

SIGMA

I

K

people

.EN

J (4)

452

4Y\-\- 4 people—^^41.1 Kpeople

Spacing and Lines: Before we enter more complicated equations it is necessary to describe how the eqn and neqn preformatters handle spaces between words, characters, and lines.

eqn

(a)

Spaces are used to delineate the “pieces” of an equation. For instance:

.EQ 5

OMEGA

times 6

= sum

+ LAMBDA

x dot

.EN is

formatted

as:

50 x6=^;c+A If

some of

the spaces are not included:

.EQ

50MEGA

times 6

= sumx

dot

+ LAMBDA

.EN the formatted equation

comes out looking

quite different:

IOMEGA x6=5w/7ix+A When

comes

50MEGA

does not recognize the string of characters as code for any symbol, so the string is printed out as is. Likewise, because sumx is not in its the formatter

repertoire,

the

sumx

is

to

printed.

it

Then eqn

follows the dot

instruction by placing a dot over sumx.

Summary: Spaces

are essential for the formatter to recognize

each part of instructions.

(b)

Extra spaces are ignored:

.EQ 5

OMEGA

times 6

=

sum

x dot

+ LAMBDA

.EN is

formatted with proper spacing:

5n x6=]^xTA

eqn

453

I

(c)

Use the

tilde

equation.

~

if

you want extra space included within an

For instance:

.EQ

OMEGA ~ LAMBDA ~

5 '

times

^

~

6

"

sum

~

x dot

'

+

.EN produces a spaced equation:

5

0x6=

Notice the differences

formatted

(d)

in (b)

and

in

+ A spacing between the equations as

(c).

example of diacritical marks (procedure step 2) each element was placed on a separate line, yet the output appeared as one ‘‘equation.” That is possible because the formatter treats spaces between words and the ends of lines simply as the “edge” of symbols. Thus one equation can be entered on In the

several lines in a

file.

To

offer another

example,

.EQ 5

OMEGA

sum

times 6

X dot

4*

LAMBDA .EN

.

continues to produce:

50 x6=51-^4-A This multi-line input property of eqn is especially useful trying to keep your formatting wits about you.

454

eqn

when

More Complicated Equations

Yet This

element examples of more difficult to format equations. The first seven steps describe how to effect changes in vertical spacing, such as: section

introduce

will

single

6x 3

Later

steps

together in

how

demonstrate

bracket

to

elements

which

go

more complex examples: 6U-f3)

(5)

Exponents: To have an exponent or sui^erscript added number, letter or symbol, the sup instruction is used.

to

a

For

instance:

.EQ

A

sup

+ B

2

sup

2

= C

sup

2

.EN produces a superscripted equation:

^2+52 = (6)

(^2

Subscripts: Likewise, subscripts are formatted with the sub instruction.

For example:

.EQ

X

sub

3

+ Y

sub

j

“ Z

sub

ii

+ R

sub alpha

.EN

Upon

formatting,

the

above instruction produces

a

subscripted

equation:

eqn

455

(7)

Subscripts and Superscripts: If you want both a subscript and a superscript on the same symbol, the subscript must precede the sup^/'scr/77nnstruction (alphabetical order). For instance,

.EQ

Y sub a sup 2 + X sub b sup alpha = Z sub garbage sup

3

.EN is

the instructions for sub and superscripted symbols:

ya_73

y2i ^

^garbage

a

Reversing the order of sup and sub results

in a

very different out-

put.

.EQ

Y sup 2 sub a + X sup alpha sub Z sup

b

=

3 sub garbage

.EN produces the following equation with subscripts on the superscripts:

2 ^garbage

y

(8)

Fractions:

The magic

instruction to format fractions

sider:

.EQ 30 PI over 6

=

5 PI

.EN will

produce:

30^=5n 6

456

eqn

is

over.

Con-

(9)

Limits:

Statistical or

mathematical equations

of limits on symbols such

etc.

as:

may

require the use

For example:

.EQ

Y =

from 0 sum from

int

^

to 1 1

~

x

dx

N

to inf

~

~

1

.EN The following

The

limited equation

from

instruction

is

produced:

identifies the lower limit

and

to identifies the

upper. (10) Brackets, Braces, Parentheses, large parentheses

tions

and

left

and Bars: Equations often require

around whole sections of symbols. The right

when

associated

with

brackets

and bars (the pipe) include an appropriately large symbol

parentheses

(

formatter to

),

braces

I

I,

instruc-

\

will \

{

),

cause the

in the output.

For instance:

.EQ left

A

(

over 6 ~

~

right left

)

{

3 over sqrt b right



-

~

}

left I

X dotdot over y sub alpha right

I

~

PSI

.EN The above

instructions produce:

eqn

457

(11)

Grouping Parts of Equations: What you have learned thus far will permit you to format a wide variety of equations. Problems arise, however, when it is necessary to use several elements following a format instruction (such as over or sup). Consider: ^cos a +

/

This looks like a simple figure to format. most people try is:

The

first

solution that

.EQ e

sup cos

~

alpha



+

~

t

.EN But the computer does not know that all of cos, alpha, and + t are to be placed as the exponent. In fact, it is programmed to superscript only the next symbol. As a result, the formatter produces an errant: ^cos

The way together.

^

J

avoid such surprises is to bracket symbols that go You must use, of all things, brackets { } .

to

For instance, the format instructions:

.EQ e

sup {cos

~

~

alpha

t}

.EN uses brackets to enclose those elements that are all to be placed in the exponent. The resulting output is appropriately superscripted: ^COS a

+

t

communicating with the formatter. In the previous section you were introduced to brackets

The brackets used

in this section are for

formatted equation to assist the reader. The difference is in the instructions left and right. If the bracket is used without left or right, it will be read by the formatter only as which were printed

458

eqn

in the

bracket

is

elements which

those

identifying

discarded.

together,

stay

the left or right

If

and

command

then

the

precedes the

bracket, the formatter will include the appropriately sized bracket in the final output.

(12)

Examples

of

Complex Equations Using Brackets: Each of

the fol-

lowing equations includes brackets that identify entire sections of the equations which need to be treated as units. Any complex group of symbols, letters, and numbers, if surrounded by brackets, can be used where just one symbol normally would be used. ations of the previous examples are:

Vari-

.EQ (Example\OA) {6

(x

-f

3)}

over {sqrt (3

+

X bar)}

.EN 6(x--h3)

(Example A)

V 3+x .EQ (Example\OB) {6

{(x

+

(sqrt (3

3)}}

+

e

over

sup (cos alpha}}}

.EN 6(x-h3)

.EQ (Example\OC) alpha Y~ =~ int from B sub (alpha sub 1} {

,

(Example B)

1}

to

{

delta

,

3}

+ C sub (beta sub 2} + D sub (delta sub 3} — (x + y -b z} bar .EN 8,3

y

=

J

(Example C)

eqn

459

.EQ (Example\OD)

Y {{

~ ~

~ ~

sin {(

omega

from

2 pi int t

+

to inf

1

6)}}

over {3 alpha}} •

dt

.EN oo

sin(ajr+6)

r

(Example D)

3a:

.EQ (Example\OE) ~ t

{X bar sub E ^

AT

X

bar sub C} over {sqrt {S sub X sup 2 left ( 1 over {n sub 1} •

=



~

-b

~

over

1

{

sub

2}

right

)

1.96

.EN

(Example E)



.EQ (Example\OF)

Y

=

-

sum from {

OMEGA

(i

4-

=

0}

3.7}

sqrt {alpha sub 1

to

{i

=

inf

}

over

+

beta sub 1}

.EN

r

'y /=o

n-h3.7

(Example F)

}}

.EQ (Exainple\OG)

=

sigma sup 2 ” 1 over k sup 2 sum from i = l left

1

"

to

k

(

over n tilde sub ~

over

delta sup 2

2m

{

right

i

sub

i

}

)

.EN 6

2

or

^

(Example G)

2m,

.EQ (Ex.\0H) {left

sup 2

+

(

{xi

}

over x sup 2

I

nu sup

2

}

over sqrt 6

right

1

}

"

sup 3 left

=

~

(6 sqrt (3 z times

I

OMEGA}}

over

Z sub nonsense •

-

41

+

-

right

1

psi hat

times left (

a

(

+

right

b

+

c

}

bar

)

.EN 3 1

6V3zx n

V6 x'

(13)

1

z ^nonsense

Arranging Several Symbols bols or

-41

(Ex.

a-\-b-\-c

in a Display: Vertical arrays of

numbers can be formatted with

example of

X

±\jj

this effect begins the

the pile

H)

sym-

command.

An

eqn

461

next page.

The

following instructions are interpreted to produce an equation

containing a vertical array:

.EQ

OMEGA {W

right



left

[

above 2 above 3 above

pile {1

pile

~

X

above

above

Y

4}

above Z)

I

.EN

a

The next example shows how justified

1

w

2

A

3

Y

4

Z the ‘‘piles” can be

left

or right

and rpile commands. Note the placement of elements between the two columns in

by

using

difference in

the

the formatted version.

column; the beta

Ipile

The alpha

is

against the left of the

first

to the right in the second.

.EQ

OMEGA left

I

(alpha above (2.78 over A) above (x

Ipile

4

left

I

I

rpile (beta

right

above 5.32 above (a

+

I

.EN a 2.78

13

A

x+y 4A

eqn

y)

LAMBDA)

right

462

+

5.32 -h

a-\-b

b)

above PSI)

above

The

(14) Matrices: If

command

formats each column independently. you have an array of elements that vary in height in different

columns,

pile

will

result

make

ments

in all

columns.

at

all

being

spaced

columns and

entries in the matrix.

all

that there be the

is

An

look

will

spacing decisions based on

The major requirement

columns

different

in

The command matrix

differently.

then

pile

same number of

ele-

example:

.EQ matrix ccol

~

~

OMEGA

'

left

l{

{

{alpha above

(2.78 over

A

}

above (4 LAMBDA }) ccol (beta above 5.32 above (a -f b} above PSI)

+

above (x

y)

1

1

right

1

.EN a 2.78

5.32

A

x+y

a-\-b

4A

The in

instruction ccol results in the matrix elements being centered

The

each column.

elements

at

the

left

and rcol, which place the of columns, respectively. Another

alternatives are Icol

and

right

example (and the formatted equation):

.EQ

Y

-

matrix Icol

(

ccol

(

rcol

I

=

>

{

X Y Z

sub alpha above (153 + 2z) above .09 t) sub beta above (186 - 5n) above 1.3 s) sub gamma above (264 -f 3s} above 80 g)

1

.EN

1534-2Z .09/

186-5// 264+3^ 1.35

80.C

eqn

463

(15)

Type Size and Font Selection: Point

size

and type font can be

specified for individual characters in an equation or for

all

charac-

For any specific character the point size of the type can be specified by the instruction size [N] where N is a point size from 6 to 36. Here you see a 36 point Omega and 6 point “D”: ters.

.EQ size 36 pile

A

{

right

~

OMEGA above

~

left

I

B above C above

size 6

D

}

1

.EN

A

B C

by the 36 point type size specification. The formatter reverted back to standard (11 point) type for all symbols, until it encountered the next point size change command. The D was then specified to be in 6 point type.

Note

that

only

the

Cl

was

affected

In addition to point sizes, the fonts can be specified by: roman, italic, bold and fat. The fat specification makes the letter or symbol slightly

For instance, these instructions different fonts for each column:

“heavier” result in

in

whatever font

is

in use.

.EQ size 36 pile

OMEGA

"

=

~

left

I

{

italic

{A

+

14

r

sup

2)

above bold {B - 12 c sup alpha above roman {C 4- 43 d sub j above fat {D times 78 del sup 2 right

I

.EN

A-h\4r^

B-12c" C+43dj

Z)x78V2 464

eqn

}}

(16)

Changing the Exact Location

of

Symbols:

If

you are unhappy with

the exact placement of characters in the formatted equations in the

copy of your output it is possible to “fine tune” the placement of symbols. When we saw that the H in the above equation was not centered relative to the equal sign, we modified the format first

instructions as follows:

.EQ down 60 size 36 pile

OMEGA

~

^

left

I

{

{A

italic

+

14

r

sup

2)

above bold {B — 12 c sup alpha} above roman {C + 43 d sub j } above fat (D times 78 del sup 2 }} right

I

.EN The

resulting formatted display has the

Omega

properly placed:

A-hl4r^

B-

1

2c"

C+43dj

DxlSV^ The down

Number]

command

symbol or brack-

In this case the instructions

about the size of the letter (in this case 36 point), the O

is

In addition, \

affects only the next

down 60 call for the omega be moved down 60 one hundredths of an “em.” Since an “em”

eted unit. to

\

the

m is

commands up

whatever type is being employed lined up with the equals sign.

in

\

Number]

,

back Number] \

,

and fwd

Number] will re-position the immediately following symbol.

(17) Global Font or Point Size Changes: The eqn formatter will type all equations in 10 point type unless you specify otherwise. You can

any point instruct the formatter to employ a different basic point size (or type font), which will be used until you specify another. (For more information on this process see the number registers section Module Nineteen: Phototypesetting with Troff.)

at

eqn

465

The

global

command

to affect the point size of the equation

The not the surrounding text— is gsize \Number\ [7^ is used to specify the font (where \Font\ is .

Roman). For

command Italic,

— but gfont

Bold, or

instance:

.EQ gsize 14

gfont italic

==

omega

from here

int

to eternity

LAMBDA GAMMA EPSILON .EN produces an

italic,

point size 14 equation:

eternity

APE

(JL>=

here

Changes specified.

sees

fit.

and font remain in effect until a new one is The size and font may be changed as often as the author These changes affect only the equation and not the sur-

in point size

rounding

text.

Obtaining Output: Typeset:

mand

If

the output

is

be typeset, the Shell execution com-

to

is:

eqn Line Printed: execution

If

the output

command

troff

,filename\

is

to

line printer, the Shell

be sent to a

is:

neqn

[filenamel

nroff

-ms

Ipr |

with eqn: If tables are also included preformatter should precede the eqn process:

Using

tbl

tbl

466

eqn

®

-ms -Q

[filename]

\

eqn

troff |

in the file, the tbl

-ms -Q

Using refer and are included in a

cessers

with eqn: If tables, references, and equations file, the proper order for using all three prepro-

tbl

is:

refer -p database

filename

eqn

tbl

-ms -Q

troff

®

Command

sequences include a -Q for placement of the job in the troff queue. If your installation uses some other troff queue procedure, remove the -Q and substitute the proper argument. Note: Three of the above Shell

Detecting eqn Format Problems: UNIX maintains a program which

check your equations for formatting errors. Before you have a paper containing sophisticated equations formatted you might want to let checkeq review your work. The program isn’t foolproof, but it can be of some help pointing out possible trouble spots.

will

The

Shell

command

line to

use checkeq

checkeq

filename

Additional Reference Material:

Two

is:

page pamphlets

in

wide distribu-

tion are:

TBL— A

(a)

Program Laboratories, and

(b)

Typesetting

to

Format Tables, by Lesk, published by

Mathematics— User’s

Guide,

by

Bell

Kernighan

and

eqn

467

Cherry, published by Bell Laboratories.

Module Twenty-Eight Troubleshooting

Introduction Problems encountered while using UNIX are both frustrating and not uncommon, owing in part to the complexity and power of the system (and the vagaries and moods of any electronic beast). This cannot be a comprehensive section, due to the incredible variety of We have, however, errors possible with the UNIX system. attempted to address the more common problems encountered by us and the many UNIX users with whom we have worked.

Prerequisites Before using (so,

what

this

else

is

Module you should have encountered

a

problem

new?).

Objectives After reading the diagnostic section of this Module you should, in many cases, be able to locate the appropriate remedy for your

problem in the second where to start).

468

part of the

Module

(or

have some idea as

to

Procedure The procedure section of this Module is presented in five parts. The first section is designed to help you diagnose your problem. you to the the Module where the remedy to your

This material should be read carefully, as appropriate location (s) in

it

will direct

problem may reside. The remaining four sections include descriptions of the most common problems we have encountered and our These problem-remedy paragraphs are suggested solutions. presented in four major groupings: /

Problems Logging On;

-

II

Unexpected Formatted Output;

-

and Error Messages; and

III

-

Shell Problems

IV

-

Editing Problems.

Each of these groupings begins with an index to the problems it addresses. The diagnostic section will refer you to the appropriate solution section.

The lier

section entitled Resetting Your Terminal Type referred to in ear-

Modules

is

part (H) of section

IV

-

Editing Problems.

Diagnosing the Problem working with UNIX you know you’ve got a problem when something unexpected happens (why did that funny message appear on my screen while I was editing this file?) or when you accidently do something resulting in an expected, but undesirable outcome (why did I delete the first thousand lines from the report To begin diagnosing your problem you I just finished editing?). should consider in which category your problem falls:

When

(1)

you are experiencing difficulty logging on the system, proceed directly to the first problem-remedy section

Problems Logging On: to

of this

(2)

Module

If

entitled Problems Logging On.

Unexpected Formatted Text Output: If your problem unexpected output of formatted text proceed to the problem-remedy section: Unexpected Formatted Output.

Troubleshooting

is

with

second

469

(3)

The other unexpected or undesirable Module can be classified as occurring either

Shell or Editor Problem:

events covered

in this

while you are interacting with the Shell or with an editor.

you know you were interacting with the Shell when your problem occurred proceed to the third problem-remedy section of this Module entitled Shell Problems and Error Messages. If

If

you were

in

an editor

occurred proceed to the

Mode when

final

the troublesome event(s)

problem-remedy

section: Editing Prob-

lems.

you are not sure where you were when the trouble began continue to procedure step (4), which follows. If

or

RUB

DEL or logged on you should press the |DEL

RUB

DEL

(4)

key can be your If

you are

light

still

through the darkness,

key.

nothing happens you are probably no longer in communication with UNIX. This means that either your keyboard has locked up, or the system has crashed or that you have in some other way been disconnected from the system. In this case we can offer little assistance and suggest you locate an experienced user near by or talk to whoever administers your local system. (As software types we can only offer the time honored response, '"Hey, what can I If

say? That's a hardware problem."')

communication with UNIX when you pressed the DEL or |rub| key one of three things probably happened:

If

you were

in

I

The terminal' "beeped". You are in the visual editor. If you were in Command Mode, you were left there and the beep sounded. If you were in Append Mode you were move d to Command Mode and the beep sounded. (The |DEL| key

works

Mode

like the |ESC| key, in that if

minal to (b)

moves you

to

Command

you were in Append. It will, however, cause the beep regardless of which mode you were in.)

ter-

The word "Interrupt" appeared on the screen. You are in the line editor. If you were in the Append Mode, you have been moved to Command. If you were in Command Mode, you

remain there.

470

it

Troubleshooting

A

(c)

process.

mark appeared on the screen. You were in a Shell By pressing the |DEL| key you ended the process

(killed

and are presented with another Shell prompt.

question

it)

At this time you should know were you are and have two choices about how to proceed. If you feel like your problem is solved — and have no need for further information — then continue with your work. If you desire to know more about the troublesome event you should examine the index of the appropriate problemremedy section of this Module and read the related information.

Organization of Problem-Remedy Sections: Each of the following problem areas is divided into symptom categories {A,B,C, etc.). Each symptom has listed under it one or more possible causes. The proposed remedies (identified with a •) are placed below each of the symptoms.

Section I

-

Problems Logging

On

INDEX (A)

No Cursor

(B)

Strange Characters Appear on the Screen

(C)

Cannot Get Logged In

(D)

No Login Banner

PROBLEMS

and

REMEDIES

No Cursor (1)

Brightness turned down, or terminal in,



is

not on,

not plugged

or in need of repair.

Make

turned up, switch is on, the terminal is plugged in, and you have given it 15 seconds to warm up. If still no cursor appears, try another terminal and report the problem. sure the brightness

is

Troubleshooting

471

(B)

Strange Characters Appear on the Screen Switch settings of terminal are wrong.

(1)

• Try a dilferent terminal. • Examine a similar terminal for proper settings.

Terminal

(2)

is

receiving noise from line or

modem.

• Try a different terminal. • Logoff (hangup phone and/or turn off the modem). second time.

Logon

a

• Report problem for service.

(C)

Cannot Get Logged In Error

(1)

made

in

entering either the login or password.

• Carefully enter each “word,” leaving no spaces between the characters in your login and password. There probably are no upper case letters or spaces in either (upper vs. lower case is critical).

The system does not recognize

(2)

either the

password or

login.

• First be sure you are correctly entering the “words.” Then check with the system administrator to be certain that you have an exact copy of a working password and account login.

(D)

No Login Banner (1)

Dead

connection with UNIX central.

• Try another terminal.

• See

if

anyone

else

is

logged into your system.

• Call the system administrator. (2)

System went down.

• Scream,

472

cry,

Troubleshooting

go play tennis; see system administrator.

Section 11

Unexpected Formatted Output

-

Many

formatting problems can be identified in advance of actually formatting the file by employing the check nxoff program. From the Shell enter checknr filename to locate potential problems.

Module Nine

for

more information about

See

the checknr program.

INDEX (A)

No Output

(B)

Margin

(C)

Extra Underlining

(D) Text (E)

Is

Not Where

Not

Is

Should Be

Filled

Missing Text

PROBLEMS (A)

It

and

REMEDIES

No Output Entered incorrect

(1)



Make

certain

command

the

Shell

line.

command

contains

all

the

proper

has the appropriate arguments (each separated by a space), and that the command line calls for the right

pieces, that

it

filename.

(2)

Logged out before job was finished.

• Unless your account is set up to continue work after logging out you should not do so until all processes are completed. Module Seventeen: Backgrounding a Process describes how this can be done. (3)



File contains

unbalanced

.DS, .KS, etc.

have a Table Start without a Table End or a Keep Start without a Keep End? Pairing these commands is essential. Check that you have not forgotten to match each .FS, .DS, or .KS with a matching .FE, .DE, or .KE.

Do you

Troubleshooting

473

(B)

Margin

Should Be

It

has unbalanced indent requests.

File

(1)

Not Where

Is

• Check that for each .RS there

is

.RE

a

to return the

margin

to its original position.

File includes

(2)

mixed .RS and

.in

formatting commands.

• These commands do not access the same number registers. Thus, indenting can quickly become fouled up when both are used. For this reason you should stick with one or the other. Error

(3)

in specification

of margin.

• The units you use are

critical.

For instance,

five spaces, while .in 5i indents five inches.

5P

.in

(C)

(pica)

does not equal

.in

.in

To

5 will indent

the formatter,

5p (points).

Extra Underlining

An

(1)



unbalanced one-way underline

command

used.

probably began underlining with the .1 command. You must return to non-underlining status with the .R command.

You

(When

using nroff both the .B and .1 result in underlining.) In addition, section headers are underlined if you use the -ms

macros.

(D)

Text

Is

Not

Filled

Unbalanced nroff requests.

(1)



You

probably inserted a .nf to isolate a block of unfilled text,

and did not include the matching Text does not begin at

(2)



A

line

left

.fi

command.

margin.

of text which does not begin

at

the

result in a blank space in the formatted text. lines in

(E)

file

begin

at

the

left

margin.

Missing Text ( 1 )

474

your

A

text line begins with period or apostrophe.

Troubleshooting

left

margin

Check

will

that

all



An

input line beginning with a period or apostrophe

is

con-

sidered by the formatter to be a formatting instruction and not text.

Make

certain that the missing text

is

not on a line begin-

ning with a period or apostrophe. Illegal text

(2)

included on a formatting

is

• Although a few formatting (.IP

commands

command

line.

take text as arguments

Any

(A) for instance), most do not.

text placed

most formatting requests will be ignored. instance, this input line would not print:

line

with

.ul distinguished scholars

Section III

-

Pulos and

Shell Problems

on

a

For

Chang

and Error Messages

INDEX (A) Messages Appear on the Screen

My

Prompt?

(B)

Where’s

(C)

Lost in a Directory

PROBLEMS (A)

and

REMEDIES

Messages Appear on the Screen (1)

Command

not found.

• Usually means the (2)

command name was

misspelled.

Cannot open filename.

• Usually means the filename you included in a command line is not in your current directory, or you incorrectly typed the filename. (3)



Broken

You

Pipe.

probably deleted the job while

it

was being executed.

Try reissuing the Shell Command (or, if wealthy, call a plumber). May also occur if the Shell must break a process for any reason (for example, if you route a formatting job into an already t\\sX\ng filename) Troubleshooting

475

Stopped.

(4)



note reading Stopped appears at the bottom of the screen, along with the Shell prompt, press these keys: If a

®

fg

(The source of your problem was pressing of the CTRL-Z key, which places a process into the background and gives you a Shell prompt. The command fg means lore ground, dind pulls this backgrounded process into the foreground.) There are Stopped Jobs.

(5)

• Will occur when attempting to logout and you have put a job into the background (with the CTRL-Z command). See (4) above.

Permission denied.

(6)

• Usually indicates you forgot to include the command in the command line. You probably entered a filename alone rather than a Shell command followed by 2 filename. i

you specified does not have execute permission. You must change the mode of a file to 700 for it to be executed. See Module Twenty-Two: Commands, Files, and Directories.

• The

(7)



(8)

file

Core dumped. was abnormally terminated. A file named core, containing an image of core at the time of termination, You may remove this core is added to your home directory. file and suffer no ill effects.

A

Shell process

Usage:

.

.

.

• Indicates incorrect use of Shell command (i.e., too few or too many arguments). For example, if you use cp with only one filename in the command line you will get a message something like the following:

Usage: cp fl f2; or cp [

Attempt

-r

] fl

to decipher the cryptic

to use the

command

and enter the correct Troubleshooting

... fn d2

message

(and just

made

command

line.

or, if

you know how

a typing error), ignore

it

(9)



No

match.

You were

probably using a filename expansion character to locate a file. No filename exists in the current directory that fits the expanded file name as you specified it. See Module Sixteen: Account

(B)

Where’s (1)



My

Stuck

in

Management

Activities.

Prompt? a Shell process.

you entered a Shell process (such as Mail or write) you (See will remain there until you end it. Try using a CTRL-D. Module Fourteen: Communicating with Others for assistance with Mail and write.) If

• Other Shell commands can have a similar effect. If you entered vi without specifying a filename, the visual editor will be invoked. You will be in the Command Mode, and can return to the Shell by entering :w filename (to save the file material) and

(C)

ZZ,

or :q! (to trash

it).

Lost in a Directory (1)

Do

not remember which directory

• Enter (2)

Want

pwd

to discover

• Enter the cd Shell

Home

in.

your current “working directory.”

Home

to return to

you are

directory.

command and you

will

be placed

in

your

directory.

Section I V

-

Editing Problems

INDEX (A) Deleted

Wrong Text from

(B)

Made

(C)

Display Went Blank

a Complete

(D) Display (E)

Is a

Mess

File

of File

Word Salad

Messages on Screen

Troubleshooting

477

(F)

Strange Characters on Screen

(G)

Numbers and Text Crammed Together

(H) Arrow Keys Don’t

Work

Correctly (Resetting

Your Ter-

minal Type) Cursor Skips Lines

(I)

PROBLEMS (A)

Deleted

Wrong Text from

and

SOLUTIONS

File

And you

(1) (2)

tally

have not entered another removing the text.

• Press the u key one time. last modification to the file.

You deleted the retrieve

text

This undo

several steps

since acciden-

command undoes

the

back and u does not

it.

(3)

• The visual editor saves the buffers

command

numbered

1

to 9.

last

To

nine

(9)

text deletions

access these buffers type

in

"#p

(double quotes, [1-9], p). If the desired text does not appear, type u (for undo), and then press the period (.) key. You can repeat this procedure (u.u.u.) until the desired text appears. See Module Thirteen: Truly Advanced Visual Editing.

Error was too far back for numbered buffers. •

you would rather go back to how the file was before you began this editing session (or last typed the :w command) you can return to the Shell without writing the present version onto the permanent memory. To perform

You have

a choice: If

this action

you:

First press the |ESC| key;

(b)

(B)

Made (1)

Second type :q! and you will return work of that editing session vaporized.

a Complete

May

Mess

of File

be caused by a variety of reasons.

• See (A) 3 directly above.

478

Troubleshooting

to the Shell, with

(C)

Display Went Blank (1)

You pressed ctrl-Z and stopped

• See Section III

(D)

Display ( 1 )



Shell Problems paragraph

From

the

(Z minus



(4)

Stopped.

be caused by a variety of reasons.

Command Mode

press these keys

®

z-

(2)

A

Word Salad

Is a

May

-

the process.



^

clear

and redraw the screen).

Your terminal needs

to

be

reset.

your screen regularly fouls up during an editing session (one common problem is text in your file cramming up against the line numbers displayed on the screen) try the folIf

lowing: Place yourself in the Shell, type

®

reset

and then again attempt

(E)

to visually edit a

file.

Messages on Screen (1)

Could be a note about completed process or a from another user.

write

message

• See Section III - Shell Problems for a description of various screen messages. •

message from another user, you might want to write back. See Module Fourteen: Communicating with Others.



If

If

it

a

you are

rid

(F)

is

of

it,

staring at a

message from UNIX and

just

want

to get

enter z- to redraw the screen.

Strange Characters on Screen (1)

Screen displays characters such as

"

PT f IC L.

Troubleshooting

479

You

probably tried to

while in the

move

Append Mode.

the cursor (using the arrow keys) These are th e control characters

Command Mode. Remove

move

Press |ESC| to

those keys.

associated with

into

the

the control characters, and con-

tinue your work.

(G)

Numbers and Text Crammed Together Momentary power outage

(1)



or other terminal disruption.

there was a power failure-— or you momentarily turned the terminal off— the text may be jammed against the editing If

numbers. Enter: (1)

(H)

reset

Arrow Keys Don’t Work Correctly (Resetting Your Terminal Type)

Login •

You

error.

probably

made an

error in informing

terminal you are using. enter the

command

To

command

will,

give yourself a second chance

(don’t forget the dot in .login):

source

This

UNIX of the type of

among



login

other things,

tell

UNIX

to ask

you

once again what type of terminal you are using. Refer to the section Accessing the UNIX System in Module Two for help with this step.

(I)

Cursor Skips Lines (1)

You did not use

® at the end of each

• What appears to be a discrete tion

of the prior line(s).

two or more screen

lines.

A

line

line.

of text

is

in fact a continua-

single very long line

You

is

occupying

probably noticed while entering

the text that the cursor automatically returned to the

of the screen; thus you did not press the

®

key.

left

The

side

result-

one line to the editor. Place the cursor on a space between two words, press r and the key, and the line will be divided into two lines. ing several lines of screen text are in fact only

®

480

Troubleshooting

Module Twenty-Nine

Where

to

Now?

Introduction Congratulations!

You have reached

the

Module in this book. of the UNIX operating syslast

So far, you have been using the features tem that we identified as most important for text processing and program writing. There are several other, more complex features also available on most UNIX systems which this final Module will briefly introduce. References will be provided for more thorough investigation.

• Prerequisites Before starting this Module you should have completed Modules One through Twelve. rnrcoog

Objectives 29 Upon completion

Module you

have introductory knowledge (and be able to access the appropriate documentation to learn more) about the following UNIX programs and resources:

(0

Sec/,

a

of

this

stream editor similar

in

will

command

syntax to the ex line

editor; (2)

a pattern

scanning language;

»

481

^ ^

(3)

Shell programming,

a

method used

create powerful Shell

to

scripts; (4)

C-Language,

the

programming language

in

which UNIX

is

written; (5)

data-base

a

Ingres,

management system

on some

available

UNIX systems; (6)

ISP and

(7)

Writers'

S,

and

interactive statistical packages;

Workbench,

a

collection

of programs

increase the overall effectiveness of written

work

designed

to

(particularly

helpful with technical writing).

Procedures This procedure section is presented in seven parts. In each section you will be provided with a brief description of a selected UNIX resource. Several of the descriptions include examples. You may wish to try out the examples presented, but this is not essential for understanding.

Sed, the Stream Editor Sed ex

is

an editor which performs

line

many

of the same functions as the

The

but in a different manner.

editor,

line

editor,

ex

command of a series to all lines in the file. Then second command is applied to all lines, etc. Sed, which is a

applies the first

the

stream editor, works

commands

to

one

next line of text,

line

in the

opposite way.

of text, then

it

It

applies

applies all

all

specified

commands

to the

etc.

The Sed editor is most useful when included in a series of ‘‘piped” Shell commands, because it performs its functions on the standard output to the standard output (the standard input and output were described in Module Seven). input and routes

its

For example, the following command sequence will format the file named test, remove all blank lines from the input, and send this abridged text to the page command: nroff

Where

to

Now?

-ms

test \

sed V"$/d'

1

page

®

Note how sed uses language

a

command

syntax very similar to the ex editor

(in this instance the special editor characters

Sed— A

Documentation:

Non-interactive

Text

and

Editor^

$).

from

Bell

Laboratories.

A wk, Awk

the Pattern

a pattern scanning language.

Scanner

very useful for performing more complex searches than are possible with the ex or sed editors. In addition, awk can be used to write simple programs which do not require detailed specifications. is

It

is

For example, the following procedures could be used to select from a large file all individuals taller than 70” who wear shoes larger than a size eleven: (a)

Create a

file

(referred to here as data) containing the per-

tinent data:

name

height

shoe

Paul-Johnston

71

Harold- A tkins

72

10 12

H- Dan-Smith

73

Lyle-Strand

70

10 10

Walter-Mitchell

73

9

Each of the above lines contains three pieces of data. In this example each record is on a line by itself and each datum is separated from the others by blank spaces. (b)

Create a second program: {if

(

file

(here called program) containing the

$2> =70 && $3> =11)

print $1

awk

)

“find the record(s) that have a second field (data point) greater than or equal to 70 ($2> =70) and

This line translates

(&&)

as,

a third field greater than or equal to 11

these cases print the

first field

($3>=11) For

(print $1).“

Where

to

Now?

483

A

Enter the

(c)

that instructs the Shell to execute the

command

in the file

awk program contained tained in the

file

data:

awk In our results

program on the data con-

-f

program data

®

example this Aw^k program would display the following on your screen: Harold- A tkins

Documentation:

from

Awk—

Bell Laboratories.

Programming

Shell

Shell

and Processing Language,

Pattern Scanning

programming

lies

somewhere

gray area between using

in the

pre-packaged software and actual programming. It offers a method and for adding programming control structures (e.g. if statements) setting variables in order to create powerful Shell scripts.

For example, the following Shell program would cause the Shell to evaluate whether or not a file contained any tables and would format the file according to this evaluation. (The program must be placed

into

Commands, able (a)

a

and made executable. Module Twenty-Two: and Directories describes Shell scripts and execut-

file

Files,

files.)

Place the following lines holding the Shell program into a

(here called check)'.

#

to avoid petes

foreach

file

set if

dilemma

($argv)

a=('grep

(Sstatus

-s

==

tbl $file

TS 0)

$file')

then

nroff 1

-ms

Ipr 1

else

nroff

endif

end

484

Where

to

Now?

-ms

$file

1

Ipr

file

Select a

(b)

file

to

be formatted and enter the Shell

command

sequence:

check

Documentation:

from

An

Introduction to the

liam Joy,

UC

UNIX

by Steve Bourne, the C Shell, by Wil-

Shell,

and An Introduction

Bell Laboratories,

®

filename

to

Berkeley Computing Services.

C-Language UNIX

is

programmed

in the

C

This makes

language.

it

appropriate

consider writing your own C programs to supplement those already available to you as UNIX commands. Before rushing off to write a C program, however, be quite certain that you could not accomplish the intended task by using Shell commands (including to

awk and/or The piled

Shell scripts) already available

following

C program

and executed, simply

on the system.

requires a four line

file

and, once com-

prints the phrase “hi there”:

mainO (

printfC'hi there\n"); )

Note, however, that the same task with the Shell

Ritchie,

nighan

&

more

easily

accomplished

command: echo

Documentation:

is

The

Prentice-Hall

'hi there'

®

C

Programming Language, Kernighan & Publishers, and UNIX Programming, Ker-

Ritchie, Bell Laboratories.

Where

to

Now?

485

Ingres

Ingres

a data base

is

sions of UNIX.

It is

management system

available

on some ver-

useful for maintaining and updating large data-

bases which require frequent report generation.

Documentation:

A

Tutorial on Ingres

Database using Ingres^ both by E.

and Creating and Maintaining a Epstein, Electronics Research

Laboratory, College of Engineering, U.C. Berkeley.

ISP and S

buted by the University of buted by Bell Laboratories. tistical

analyses

— including

highly interactive manner.

learned and so

makes

more powerful and

ISP is distriCalifornia at Berkeley, and S is distriEach can perform many common stamultiple regression and T-tests — in a Of the two packages ISP is more easily

interactive statistical packages.

ISP and S are both

a very useful instructional tool.

S

offers a

sophisticated system.

Documentation: ISP is described in A Tutorial Introduction to Berkeley ISP, from UC Berkeley Computing Services; S is described in S—A Language and System for Data Analysis, from Bell Laboratories.

Writers'

Workbench

Workbench is a collection of programs designed to help you improve your writing. The package can be used to identify, and in some cases correct, grammatical, spelling, and stylistic problems in your written work. There are over twenty programs within the Writers'

Writers’

Workbench

package.

most instances you access a program by typing (from the Shell) the name of the program followed by the filename you want to have acted upon. A list of several of these programs and the functions they perform is presented on the next page. In

Where

to

Now?

Selected Writers

'

Command

Workbench Programs Function

findbe

file

Identifies

org

file

Prints text structure of file.

diction

file

Identifies

splitrules

suggest

words

Explains

all

forms of verb

to

troublesome syntax

be in

file.

in file.

split infinitives.

Suggests alternatives to words.

style

file

Analyzes surface characteristics of file.

topic

file

Locates frequent noun phrases

proofr

file

Invokes several Workbench programs which check spelling, punctuation, double words, syntax, and split infinitives.

punctrules sexist

[file

in file.

Displays rules enforced in the proofr program. Identifies sexist phrases in

file.

Where

to

Now?

487

Shell

Command Summary Special Characters

Command

Function

Routes standard output from a prior Shell

I

command

>

next Shell

command

to a specified

file.

Routes both standard output and error from a prior Shell

command

into a specified

mand ;

line.

Allows you to type several Shell

on one the

$$

;

line

(each

command

is

commands

separated by

).

ID of current

UseFor ful for generating a unique filename. example, vLn\(\file > file.%%, results in a new containing uniqw^ lines and named file where somenumber is the file, some number,

Expands

to process

Shell.

process ID of the parent Shell. ?

488

file.

Causes Shell command line to run in the background when appended to end of com-

&

*

(Pipe).

Routes standard output from a prior Shell

command

>&

to the

Matches any

single character.

Matches any sequence of characters.

Commands

Shell

Command alias

0

awk

1

command

\pro^\ [filel

Function

Makes x an

alias for a

awk program on

Executes an high

command

line.

filel.

awk

is

a

scanning and numerical programming language very useful in database management.

batch

scriptfile

cal \month\ [year

cat

[filel [file

pattern

level

Executes a batch scriptfile. Almost any job can be submitted to batch, which can normally run a job more cheaply then interactive work. Prints a calendar for the specified year

1983).

A

number

(1-12) before the year.

Concatenates catenated screen. If

is

By

file(s).

>

specified

by

the

default,

a

con-

be displayed on your to redirect output to new file. will

file(s)

Use

output

may be

month

(i.e.,

displayed on screen, press CTRL-S

to halt scrolling.

s cd [directoryname

Changes directory ryname must be

to a

directoryname

subdirectory

{directo-

of current

directory).

checkeqn

[fUel

check5

filel

(containing eqn constructs)

for

problematic eqn commands. [filel

checks

filel for

clikps

checks

process

checknr

some

(Available

E L L

C

nonbalanced formatting constructs {nxoff and -ms commands). status.

H

only

on

systems.)

O

M M A

N D S

Shell

Command Summary

489

Command chmod mode#

filel

Function of filel to mode# (which specifies the permissions attached to a file). Permissions are read, write, and execute per-

mode

changes

mission for owner, group members, and others (see

dear col

Module Twenty-Two).

clears screen and places cursor at top.

reverse line feeds from a text file. used as a filter when piping output

Removes Often

from

tbl

an output device that can’t do

to

reverse motion

comm

filel

file!

filel

cp filel file2 crypt

line printer).

words common to two sorted lists (filel and filel). Identifies words in one file and not the other or words found Selects

both

in

compact

(i.e.,

or

rejects

files.

Reduces disk space occupied by file, compactet/ version of filel will have .C appended to filename (filel. C). Must use uncompact before editing or otherwise using file (if this command does not work for you try pack and unpack).

compacts

filel.

Creates a second cop>^ of filel called £/ crypts and decrypts a 7

file

(see

file2.

Module

Six-

teen).

date dc

deroff filel

Displays the current date and time.

Performs arithmetic calculaEasy to use once you learn assembly tions. language programming.

desA: calculator.

Removes

formatting constructs from filel (de

//roffs a file).

diction filel

490

Shell

Identifies problematic diction in filel.

Command Summary

Command dirs

Function

Displays pathname of current directory: dir^c-

(Works faster than pwd but only available on some systems.) tory status.

du

displays disk usage in blocks.

is

(Available only

on some systems.) echo

string

eqn

[filel

Displays (echo6’s) string on screen.

Preformats all equations in filel. Output should be piped to the trojf formatter (use

neqn

as a preprocesser for /7ro#formatting).

Recalls a backgrounded process into the ior-

become your current only on some systems.)

grounfi this process will (Available

process.

find

find5 file specified with -n option.

-p option to

pathname of file ^printed Fifteen, The UNIX Directory

have

Module

(See

Must use

full

Structure)

grep

strin^\ [filel

Locates

all

instances of string (a global regular

expression or ipattern) in filel.

head

[filel

history

Displays

ten lines (head) of filel.

first

Reports history of

commands, where

last

#

is

# number

of Shell

number

that his-

the

tory variable has been set to.

with

jobs

C

(Available only

Shell.)

Displays

list

of

processes

(jobs)

currently

stopped or running in the background.

kill

#

process logout

number number (#).

kill5 process

(#); kill -9

#

will

nuke

Ends communication with UNIX.

Shell

Command Summary

491

2

Command look

[string

lookbib database

Ipr

[ft lei

Function looks in dictionary for words that match string and displays on screen this list of words. looks through a hihliographic database file for references containing specified keywords.

Causes

copy of

a

filel

to

be printed on the

\ine printer.

Is

Displays a

1/st

of

all

files

in

your current

directory.

mail

[lo^in

man command

Sends a message to login. End message with a CTRL-D (see write). When used without a login as an argument initiates a mail receiving session and displays a list of all messages sent to your UNIX account. Displays the

UNIX msmual information about

whatever command you

mesg y

or n

Permits other user to write mes^7g^5 to your terminal (and you to write them). Default value

mkdir

directory

more

mv

[ftlel

[ftlel\ [file

specify.

is

m^7k^s a

yes (n for no).

new ^uectory named

Displays filel one Similar to page.

directory.

more window

mov6»5 filel into filel (changes

at

name

a

time.

of filel

to filel).

neqn

[ftlel

nroff

[ftlel

Output Preformats all equations in filel. should be piped to the nroff formatter (use eqn as preprocesser for rrc# formatter).

Formats

filel

according to

nroff

commands

embedded in the text (n^’w run off). Must use nroff -ms to format filel when -ms macro calls are embedded in the text. 492

Shell

Command Summary

Command

Function

pack

[filel

pack5

page

[2^

Displays filel a page at a time (file can not be edited, only viewed). Similar to more.

passwd ps

pwd

Reduces disk space occupied by version of filel will have .P file. }) 2LQked appended to filename ifilel.P). Must use unpack before editing or otherwise using file (if this command does not work try compact and uncompact). filel.

Changes your passwo/tl. Provides process status information will provide more global information).

(ps -g

Displays pathname of current directory (print yv or king directory).

refer

[filel

Prepares filel containing refer bibliographic fields for formatting by a macro package (i.e., -ms).

reset roffbib

[filel

resets terminal to a sensible state.

out fields from a bibliographic data base as endnotes instead of footnotes (as refer does). Generally used with sortbib as Prints

follows; sortbib filel

rev

[filel

revmcs but

rm rmdir

I

[filel

directory

sed

it’s

all

roffbib. |

lines in filel

(why? don’t ask

great fun).

removes filel (be

careful!).

removes directory directory. tains files you must use rm stream

us,

editor.

ful as a filter

(If directory

con-

-r directory.)

Uses ex-like syntax. Most useto modify information passing

through a pipe.

Shell

Command Summary

493

.

Command set

set noclobber

Function With no arguments set displays variables have been set for your account.

that

Prevents overwriting (clobber/>7^) an existing file.

set ignoreeof

Prevents CTRL-D from logging you out of UNIX (ignoreeof — ignore end of file\ CTRL-D is the UNIX “end of file” message). "

sort

[filel

sorts filel into ascii sequence.

sortbib

[filel

sorts a hWiliographic data base (see roffbib).

source

[filel

Asks

Shell to execute filel containing Shell

commands

(uses filel

Most

Shell).

tail [filel

code

in filel

for

file.

Compares spelling of all words in words in UNIX dictionary and reports found

stty

source

useful for requesting Shell to

re-read your .login spell [filel

as

and not

filel all

to

those

in dictionary.

Sets terminal type parameters.

Displays

last

ten lines (tail) of filel.

thWMl

Preformats all tables in filel. Output must then be piped to the nroff ox trojf ^oxm 2d.Xex

tee [filel

tee

Catches output within a pipeline and puts a copy in filel. For examIpr will format tee ntext ple, nroff textfile textfile and place a copy of the formatted output in ntext while sending an additional copy is

a pipe fitting.

\

\

to the linepr inter.

translates

some

specified characters or range

of characters from the standard input into a different

set

of characters

and sends

translation to the standard output.

494

Shell

Command Summary

this

Command troff

[file I

Function

Formats

embedded

in

commands

according

to

the

Formatted version

filel

text.

troff

be phototypeset (typeset run off). Must use troff -ms to format, /z/c/ when -ms macro

will

embedded

calls are

tset

sets

the text.

in

terminal erase,

and other

kill,

special

characters.

uniq

[filel

Removes redundant only uniq^/c

vi [filel

Starts

a

from filef leaving

lines

lines.

or

file

an

retrieves

existing

file

Moves you into Command Mode. See summary section which follows on Commands to Enter an Edinamed

filel

for

y'xsual

editing.

tor.

wait

Causes Shell

wc

[filel

Shell

wait

to

command

Displays total

backgrounded

until

complete.

is

number of

lines,

characters in filel (vtord count).

words, and

Very useful

for high school English papers that

“must be

500 words or longer.”

whatis command

Displays

synopsis

specified

command.

line

Tells

from manual for what command is all

about.

whereis command

Displays Tells

who

full

pathname of

where command

Presents a

list

of

who

specified

command.

is located.

is

currently logged onto

your UNIX system. write lo^in

Immediately wTites are logged on (see CTRL-D.

Shell

to login while niuil);

both of you

end session with

Command Summary

a

495

Commands

Enter an Editor

to

Command

Function

vi [filel

Starts

a

named

filel

into

vi

H-#

[filel

or

file

retrieves

an

existing

file

Moves you

for \\sual editing.

Command Mode.

Puts you

Mode

the

into

at line

#

yisual editor

in filel.

If

#

no

Command is

specified,

places cursor at last line of filel.

vi

+/

I

word\

[filel

Moves you

Mode vi

at first

when

Moves you [filel

instance of

editing

into

Shell

in filel.

or

retrieves

Starts

a

named

filel for line editing.

file

Command Summary

terminated.

session

Command Mode.

the (extinct) line editor

496

word

Command

Creates a buffer for yisual editing. Material must be given filename (with :w name) to be

saved

ex

into the y'xsual editor

an

existing

file

Moves you

into

Command Mode.

Command Summary

Visual Editor

• Commands

Cursor Moving

Command

BEEB

Function WQ-HOeS

(h

j

k

Moves

1)

one space

cursor one line

up/down

right or left.

0

(zero)

Moves

$

Moves

cursor to the end of the current

cursor to the beginning of

line.

line.

42 (or any number).

42G

Goc5

to line

G

Goes

to the last line in

L

Positions cursor

your

file.

at

Low

point on the screen.

M

Positions cursor at

Mid

point on the screen.

H

Positions cursor at High point

w

Moves

Moves

e

Moves your

Moves word

B

on the screen.

in

your

file.

cursor forward to the beginning of the next Wo/^yin your file, ignoring punctuation.

in

b

#

cursor forward to the beginning of the

next word

W

or

in

Moves prior

cursor forward to the end of next word file.

cursor backward to the beginning prior

your

file.

cursor

word

in

Backward

your

file,

to

the

beginning of

ignoring punctuation.

497

Command

Function



Moves

cursor forward through text to next



Moves

cursor backward through text to prior



Moves

cursor forward through text to next



Moves

cursor backward through text

word

Moves

cursor

forward

through

To

text

b.

b.

prior

to

b.

b.

next

word. 9

word

Moves

cursor backward through text to prior

word.

n

Repeats

ward ter

N

)

last

/ or

?

search:

Moves

cursor for-

backward) through text to next characor word. (or

Repeats last / or of search.

Moves

?

search but reverses direction

cursor forward through text to begin-

ning of next sentence. (

Moves

cursor backward through text to begin-

ning of prior sentence.

)

Moves

cursor forward through text to begin-

ning of next paragraph.

(

Moves

cursor backward through text to begin-

ning of prior paragraph. II

Moves

cursor forward through text to begin-

ning of next section. II

Moves

cursor backward through text to begin-

ning of prior section. f /

(Two

single quotes)

tion in

498

vi

Command Summary

file.

Moves

cursor to prior posi-

Display Adjusting

Commands

Command CTRL-D

Function Scrolls dow/7 or

moves on

to

more

moves on

to

12

text in the

file.

72CTRL-D

Scrolls

down

text in the

or

more

lines of

file.

CTRL-U

Scrolls

CTRL-F

Goes forward

CTRL-B

Goes hack

CTRL-E

Displays an additional line at bottom of screen.

CTRL-Y

Displays an additional line at top of screen.

Z.

z4.

z-

z

®

CTRL-R

wp or moves back

a

to prior text.

to next block or

window of

window of

text.

text.

Redraws screen, with the current of the window.

line in

Makes screen show only 4 lines of number can be 1-23 (don’t forget the

middle

text.

The

period).

Redraws screen, with the current tom of the window.

line

Redraws screen; current

of window.

Redraw

line at top

on bot-

screen.

Undo Commands U

(lower case u) undoes the effect of the

last text

change command.

U

(Upper Case U) Undoes current

all

changes made

to the

line.

vi

Command Summary

499

Text Changing

Commands

One- Way Commands {Leave You In Append Until

You Press ESCAPE)

Command a

Mode

Function one space

Starts adding text

to the right of the

cursor i^ippend).

i

Starts adding text

one space

to the

left

of the

cursor (insert). 0

O

opens a line for text below the cursor

(Upper Case) Opens a cursor

A

line

line.

for text above the

line.

(Upper Case) Starts adding text

at

the end of

the line (Append),

1

(Upper Case) Inserts text

at

the beginning of

the line (Insert).

cw s

changes the one vford to the right of the cursor. (lower case) substitutes text for a single character.

S cc

(Upper Case) Substitutes text for an entire Substitutes

same

C

text

for

an entire

line

line.

(cchanges\

as S).

Substitutes text for the rest of the line (Changes

from the cursor position forward).

R

Replaces characters

you type over with new

characters (overlay type).

500

vi

Command Summary

^atholocy SERVltf VA MEDICAL CENTER 4150 CLEMENT street '

SAN FRANCISCa CA 94121

Text Changing

Commands

Two-Way Commands {Return You To

Command Mode)

Command

r

Function

X

Erases the character under the cursor (x out).

X

Erases the character before the cursor.

xp

Transposes characters.

0

replaces the character

under the cursor with the

letter b.

dw

deletes

from the cursor position forward

to start

of next Yford.

db

deletes

from cursor position backward

to begin-

ning of previous word.

dd

D

Deletes the entire cursor line iddeletes). Deletes the rest of the line

(from the cursor

position forward).

:T26d

deletes lines

1

through 26 (you select the

line

numbers). J

>

Shifts cursor line right

one shiftwidth (distance

of one TAB, normally 8 spaces). •

(Dot)

Repeats

last text

vi

change command.

Command Summary

501

Commands

Text Relocation

Command yy

6yy

Function

unnamed

of text and places buffer {yyanks\ same as Y).

Yanks

lines

Yanks the cursor

6

a yy

and places

(Double quotes) Yanks cursor stores in a register (registers

"

0 -^yy

(Double quotes)

Yanks

3

^7

@dd

to z available).

in

b register

of text

and

to z available).

(Double quotes) Deletes cursor stores

buffer

of text and

line

lines

stores in c register (registers

"

unnamed

in

command).

(See Put ”

in

line

{Meletes\

line

of text and

registers

a Xo z

available).

P

(Upper

Case)

register just

Puts

text

in

unnamed

line (or

before the

stored

above the cursor

cursor).

P

(lower case) ^uts the yanked or deleted text just

below the cursor

"@P

line (or after the cursor).

(Double quotes) Puts the text stored in register a just above the cursor line (or before the cursor).

"Bp

(Double quotes) pi//s the deleted text stored in register 6 just below the cursor line (or after the cursor).

Note:

last

9 text block deletions are

automatically stored in registers :1,26

m

82

:C26 CO 82

moves

lines 1

copies lines

1

1

through 26 to after

to 9.

line 82.

through 26 and places after

(52.

:w Jilel

502

vi

writes current

Command Summary

file

to disk

— names

it

Jilel.

line

Command :J,26

:U26

w

»

w

Function

filel

yv rites lines

filel

Appends

1

new

to 26 as

lines

— names

it

filel.

26 to end of existing

to

1

file

file

filel.

:26 read file!

Places contents of filel into current line

after

26 {reads mfile).

Commands

Miscellaneous Additional

:sh

processing— places current file in background and moves to the shell (return to file with CTRL-D).

'Acommand

Temporary Shell escape. Insert whatever Shell command you wish. Output from command, if any, becomes part of current buffer.

Q

Stops

Moves from

Mode CTRL-G

vi

the

to

(Return to

vi

with vi

file

file:

displays filename,

RETURN

CTRL-Z

Stops processing— places current with

available

U]

abc

Creates 1)

to the Shell

file

in file.

line.

in

back-

(return to the

command).

the fg Shell

Note: Not

on some systems.

own Command Mode command. You and

abc

any

(#1 for function of

actions

for

phrase

Command Summary'

503

with

(remove with :unmap phrase

one

character: advances cursor

replace $ with any character

key

Command

command).

CTRL-M

file

abc

editor

and cursor position

edited,

ground and moves

:niap

line

Status check of current

percent of

:ab

file

series

$).

abc as dH^breviation (remove with :una abc).

Establishes

17

Quit Working on the File and

Return to Shell

Commands

Command ZZ

:w

®

Function changes made to the file during an editing session and returns to the Shell (the “I am finished working on this file” command).

Writes

Yirites all

you the :q!

®

®

the changes

made

in the visual editor to

and leaves continue working on in a file

file.

an editing session and returns you Shell, but does not write changes made to

to

Qiuits

(the

:wq!

all

“can

I

start

over” command).

changes made in a file during an ing session, quits and returns to the Shell.

writes

file

all

edit-

Regular Characters for Search and Substitutions

c

When

placed at end of search

confirm substitution. tution; press

d

When

® to

it

prompts you

to

Enter y to execute substi-

cancel

it.

placed at end of search

it

deletes pattern

found. g

When

beginning of a search it addresses all lines in the file; at end of search it functions on all cases of pattern within specified lines. all

placed at

When

vi

in

both places

it

functions on

cases of pattern within current

search).

504

used

the

Command Summary

file

{global

Commands

Enter an Editor

to

Command

Function

vi [filel

Starts

a

named

filel

into

vi

-h#

[filel

or

file

word\ [fUel

Puts you

the

into

at line

Moves you

Mode vi

#

[filel

Command

\isual editor

in filel.

If

no

#

is

specified,

filel.

into the yisual editor

at first

Command

instance of word \n filel.

Creates a buffer for \\sual editing. Material must be given filename (with :w name) to be when editing session terminated. saved

Moves you ex

file

Moves you

\isual editing.

for

places cursor at last line

+/

existing

Command Mode.

Mode

vi

an

retrieves

into

Command Mode.

or

retrieves

Starts

a

named

filel for line editing.

file

the (extinct) line editor

vi

an

existing

file

Moves you

into

Command Mode.

Command Summary

505

Special Characters in

Command

Append Mode Function

BACKSPACE

Backspaces one character.

Append Mode and Command Mode.

(rubout)

DELETE

you

in

ESCapes

ESC

CTRL-H

Interrupts

to

places

Command Mode.

Backspaces one character.

CTRL-I

TAB

CTRL-V

Allows input of a SPACE, TAB, or

character

(moves

8 spaces right).

RETURN

char-

acter.

CTRL-W

Backspaces one word.

Allows input of a CTRL-H, BACKSPACE, or

\

character.

@

Erases

Summary Affected Text

word

input on a

line.

of Text Operators

move

to

delete

change

yank

lines

®

dd

cc

yy

to right

w

dw

cw

yw

b

db

cb

yb

word

to left

right to

g

dtg

Ct^

yt?

left to

g

dT^

cT^

yTg

right including

g

fg

dfg

cf^

yf^

including g

Fg

dFg

cF^

yF^

left

506

all

v/

Command Summary

@

Formatting

Command Summary Commands

Nroff/Troff

Command .ad b

.bp

Function

begins 2iAjusting text (this

temporary

Causes

a

begins a

new page of

is

the default state).

between

pages’,

A number

used as

break text.

an argument becomes the page

new page .br

Causes

a

(e.g.,

bieak

number

of the

.bp 4). in text filling;

begins a

new

line

of text.

# number

.ce

#

centers

.cu

#

continuously underlines for

of

lines.

next

# number

of

lines; italicizes in troff.

Begins a macro definition; replace

.de

character

macro .ds

XX

string

.fi

.ft

X

..

with two

to indicate

end of

definition.

defines string in

.ex

macro name. Use

XX

XX as

the specified

string.

(See \(*

Escape Sequences section.)

exits

from nr off ox

Resumes Changes

troff.

the Wiling of input lines (default). fo//t to

R

X where X

is

either

B

for Bold,

Roman, or S for Special Mathematical; default is Roman. Use \fX to

I

for

Italic,

for

change font within

a line.

507

Command

Function

Starts hyphenation (this

•hy .in

#

a

#

[This

left

the

is

command.]

return

.11

the default state).

margin # number of spaces. one-way command; .in 0 (zero)

indents is

is

# number

Sets line length to

(default

6 1/2

is

inches).

.Is

#

(lower case

number ing

.It

#

is

1)

(i.e.,

Sets the linespacing of paper at .Is

2 double spaces).

#

Single spac-

default state.

Sets the length of

title

to

# number

(default

is

6

1/2 inches).

Leaves right edge jagged; no adjusting. (This is a one-way command; .ad b returns to normal

.na

justification.)

.ne

#

Checks

if

# number

of output lines available;

if

premature page break occurs number of continuous lines).

not available a

(need

#

no f/7/; Stops the way command;

.nf

filling .fi

process.

returns

to

(This

is

a one-

normal

text

filling.)

.nh

.nm

# .nn

,

no hyphenates stops hyphenation. numbers next

# number

of

lines.

Stops numbering (no number).

Defines

number

register

XX

as

the

specified

value.

.pi

#

Sets ipage length at

.pn

#

Sets ^age

Format

number

Command Summary

# number

(11 inch default).

for next page at

#

number.

Command

Function

.po [#

Sets p7/ size to

Use \s#

point).

#

(default

change point

to

is

10

size within a

line.

.rd

[file

be read from file if file specified. The standard input (usually your terminal) will be read if no file is specified (see

Causes

Form .so

[file

input

Letters

sources in

to

Module).

named

file

(which

file

macro

definitions) to current

.sp [#

sp^7ccs

down # number

.ss

[#

Changes space character default is 12/36 em.

.ta

#

TAB

may

contain

file.

distance.

size

to

#

number;

# number

of characters; this distance can be a series of numbers, each indicating a separate TAB stop (default is 8 characters

Sets

to

per tab).

.ti

#

temporarily

indents

left

margin

# number

of

spaces (next output line only). Prints a three part tide line.

.ul

w

underlines next

# number

of lines;

will italicize

in troff.

.vs

#

Changes

\ertical spacing to

# number

(default

is

12 point).

.wh

#

A'A'

Calls

macro

reached; also

XX when known

Format

page

position

#

is

as “setting a trap.”

Command Summary

509

Escape Sequences Allowing Printing of Nroff/TrofF Special Characters (Special Mathematical Characters Available

Described

\S \e

Module)

in Phototypesetting

Command

Function

The backslash prevents

interpretation of a.

I

Allows printing of current escape character.

\'

Prints an accute accent in

\'

Prints a grave accent in

\-

on Troff

Prints a

minus

sign in

troff.

troff.

troff. I

\0

Creates an ''unpaddable” space the width of a 0

i

.

\

[SPACE

Creates an “unpaddable” space in the current space size.



I

\|

Creates an

“unpaddable’’ space the width of

\

1/6 em.

\&

\”

Deposits a non-printing character that occupies no space (zero width character).

When line

\d

placed at the beginning of line,

from formatter (allows comment

Shifts text

down 1/2 em

in

troff,

masks

in file).

1/2 space in

nroff.

Shifts text

\f

X

Format

em

in troff,

1/2 space in

nroff.

Changes type iont to X where B is boldface, I is Italics, R is ^oman, and S is Special Mathematical font.

510

up 1/2

Command Summary

!

Command \h'\E'

Function

Shifts right

#

distance (hor/zo/?/^?/ shift).

\v\E'

Draws

a horizontal line

\v\E'

Draws

a vertical

\o

'

#

#

Line

distance.

distance.

overstrikes characters xyz.

\P

Breaks

\r

reverses

and spreads out

filling

print

line-feed in

direction

line (pr///s).

em

1

in

reverse

troff,

nroff'.

\n([XF

Causes value stored in XX number register to be read in (where XX is a two character name for a number register). See .nr.

V(\XX

Causes string stored in XX string register to be read in (where XX is a two character name for a string register). See .ds.

\$1

Causes

argument

first

to

macro

call

to

be read

into a macro.

-ms Macro Commands Paragraph Macros .PP

Begins a standard,

five

space indented

Vara-

graVh.

.LP .IP

Begins a Left block Paragraph (no indenting).

Begins an

Indented Paragraph

the entire paragraph

.IP

fll

is

(left

indented right

margin of 5 spaces).

Begins a labeled Indented Paragraph. the

X

Replace

with numbers, letters or a word that you

want placed

to the left of

Format

your paragraph.

Command Summarv

51

Command

Function

X

Begins a labeled Indented Paragraph. Replace the X with numbers, letters or a word that you want placed to the left of your paragraph. Replace # with a number indicating indentation

.IP

of paragraph.

QP

Quote Paragraph. Indent 5 spaces from both left and right margins. Automatic Begins

a

single line-spacing not provided.

Begins an QXdented 'Paragraph. The first line of the paragraph is at the left margin, while the

.XP

remaining lines are indented.

Footnotes, Keeps,

and Displays

Text between an .FS and an .FE command is formatted as a footnote. Footnotes are not numbered. (Some systems will allow you to produce numbered footnotes. To do this you must also place these three characin the text where you wish the numters bered footnote to appear.) (.FS is a one-way command; .FE is the return command.)

.FS

Starts a footnote:

.FE

Ends

.KS

'

a footnote:

Starts a Keep:

command

is

Returns to normal text layout.

Text between a .KS and a .KE

printed on a single page.

neces-

If

new page is started. (This is a one-way command; .KE is the return command.) sary a

.KF

Begins a floating Keep.

If text

current page and a page break

is

will

.KE 5

1

2

Format

(This

return

command.)

Ends the Keep: Returns

Command Summary

fill

to

on

rest of

one-way command; .KE

page.

a

fit

required, text

following the keep will be used to is

not

is

the

normal page layout.

Command

Function

.LG

Increases point size by two points {harGer).

.SM

Decreases point size by two points iSMaller).

.NL

^ormaL

point size; resets point size to original

value (the value of the nr

.RS

register).

margin of text to the value specified the .nr PI register which has a default value

Indents in

PS number

left

of five spaces (Right Start). Can be repeated (This is a one-way for additional indenting.

command; .RE

the return

command.)

.RE

Moves left margin back five spaces (Right End). (Number of .RE commands used must match number of .RS commands used.)

.DA

Provides today’s DAte as center footer of paper. (This

.DA

is

\date

.ND

is

the default condition.)

DAte

Prints

as center footer of paper.

Suppresses printing of today’s date as footer on paper (No E^ate).

.2C

Column

Will format of paper. (This is a automatically cause a page break. one-way command; .1C will return to single

Begins

2

column output.) .1C

.MC

[#

Returns Sets

to 1

Column output on

column width

to

a

new

# number

Will automatically cause a break

page. characters.

page

(Multi-

(The number of columns is computed automatically, based upon line length.)

Column).

Format

Command Summary

5

1

Command .AU

Function

Centers following text line(s) as KXthor's name(s); troff sets name(s) in ten point italic type.

.AI

Centers Author’s Institution; Use repeated .AU and .AI calls for multiple authors from different institutions.

.AB

XXX

Begins

If

label. will

Absract,

nothing

is

is

entered for

not be labeled.

and adjusted

XXX

where

The

the

abstract’s

XXX the

abstract

abstract will be filled

to a line length of 5/6 the

normal

text line length.

.AE

Ends

Abstract.

Other -ms Macros .UL

word

\JnderEines word.

with the .1

Only the one word on the

.UL command

will

Begins underlining of text;

line

be underlined. will Italicize in troff.

one-way command; .R returns non-underlining in nroff and Roman type (This

is

a

to in

troff.)

.B

Bolds text, underlines in

nroff.

way command; .R returns nroff and

.R

5

1

4

type in

Draws

type in a

is

non-underlining

nroff,

will

troff.

BoX around

word.

Begins a block of text to be enclosed in a

.B2

Indicates

end of passage

Command Summary

in

return to

.B1

Format

a one-

troff.)

Stops underlining text in

Boman .BX word

Boman

to

(This

to

Box

be enclosed by

Box

Command

Function

.LG

Increases point size by two points {harGer).

.SM

Decreases point size by two points (SMaller).

.NL

NormaL

point size; resets point size to original

value (the value of the nr

.RS

Indents ing.

(This

is

a

register).

spaces

five

(Right

for additional indent-

one-way command; .RE

is

the

command.)

return

.RE

Moves left margin back five spaces (Right End). (Number of .RE commands used must match number of .RS commands used.)

.DA

Provides today’s (This

.DA

margin of text

left

Can be repeated

Start),

PS number

is

DAte

as center footer of paper.

the default condition.)

date

Prints date as center footer of paper.

.ND

Suppresses printing of today’s date as footer on paper (No Date).

.2C

Begins

Column

format of paper. Will automatically cause a page break. (This is a one-way command; .1C will return to single 2

column output.) .1C

.MC

Returns to Sets

1

Column output on

column width

to

a

new

# number

Will automatically cause a break

page. characters.

page

(Mw///-

(The number of columns is computed automatically, based upon line length.)

Column).

Format

Command Summary

515

String Definition

Commands Function

Command

X in

.ds

LH X

heft Header: Puts

.ds

CH X

Center Header: Puts all

RH X

.ds

top

X

left

corner of pages.

in top center position

of

upper right corner of

all

pages.

X

Right Header: Puts

in

pages.

X in

.ds

LF

X

heft Footer: Puts

.ds

CF

X

Center Footer: Puts of

.ds

RF

X

all

lower

X

left

in center

corner of pages.

bottom position

pages.

Right Footer: Puts

X

in

lower right corner of

all

pages.

Note: the % symbol may be substituted for X in any of the above headers or footers, and page numbers will appear in that position.

5

1

6

Format

Command Summary

Summary Register

of

-ms Number Registers

Function

Default Value (for nrojf)

.nr

LL

L/>7^

Length of text

6 inches

.nr

PO

Vage

Offset

0 inches

.nr

FL

Footnote Line length

.nr PI .nr

QI

Faragraph Indentation

5.5 inches

5 spaces

Quote paragraph Indentation

5 spaces

.nr

HM

Header Margin

1

inch

.nr

FM

Footer Margin

1

inch

.nr

PD

Between Paragraph

Iv

Distance .nr

PS

Foint Size

lOp

.nr

VS

V ertical Spacing

12p

Distances

may be

indicated in inches, centimeters, em’s, v’s, or Picas; point size and vertical spacing is specified in points.

Format

Command Summary

5

1

INDEX 1

207

(in editor)

1

r

208 111

(in editor)

1

b

345 111

nrqtf Qon{xo\ character)

(

(in editor)

171

account management

272

addbib

405

addresses, text

232

\fR

w

341

.AI

\

341

aliases

207

alias

\< \>

(in editor)

(in editor)

\fB \fl

(in editor)

A K L

49

J keys

206 44

(in editor)

goofed

/

349 252 233 139, 206 91, 290 209 274, 308 95,

(pipe) 1

(tilde)

"#P $ (in editor)

&

(in Shell)

* (in editor) * (in Shell)

® .

13 .

(dot-dot; in Shell)

268, 330

335

account customizing account establishment

394 206 206 319 319 319

\&

98

manual accessing macros access the

2

72

adjusted text

227

adjusting screen display

73

.ad .

AE

398 398 277 277

'

439

allbox, in tables

ALPHALOCK

9

key

90

alternate phrases

ampersand

91, 290

(in Shell)

any character, match apostrophe A7rQ)7control character) (

Mode

Append Append Append Append append

special characters

Mode, ex Mode, leave Mode, vi

208 345 224 191

25 49, 110 23, 129

text

99, 380

apropos

.

{moff'Qon\To\ character)

345

arguments, to Shell command arguments, within macros

.

(in editor)

208

arrow keys

/usr/lib/eign

363

/usr/lib/tmac/tmac. s

352

.AE awk

398 483

b

123

/

267

(dot; in Shell)

.

43

word

374 298

/ (in Shell) $1 (in Shell)

96

< >

117

89

BAC KSPAC E key -j

batch job, remove

»

186

batch job, submitting

? (in Shell)

308

batch processing

24,50

a

batch queue, check

A

129

batman

.AB

398

batq

107

beep beginning of line, character beginning of word, character

abandon a file during abandoning a paper ‘Abbreviation

editing

command

absolute position indicator, in nr off access deleted text

518

76

239

349 233

bibliographies, formatting bibliographies,

337 41

background a process backslash, double

bartm

92

no abstracts

90, 176, 289

341 17

298 298

297 295 298 299 298 26, 42

206 206 172, 404 414

bins bin bin

blank

searches

lines,

Bo/^/font

book conventions book objectives boxed tables boxes, trqff-ms boxes, (rqff box, in tables .bp brackets, in searches brackets, with eqn brackets, with filenames

break

command,

nroff

372 375 207 318

colon

106, 179

buffer and disk, save both

183

buffers, lettered

135

numbered

135

buffers, search

234

buffers, text storage

232 318

Bo/Jfont b

C C- Language

center text,

in nroff'

centering a table .ce

interpreters, interactive

115

interpreters, non-interactive

1

Command Mode, Command Mode, Command Mode,

leave

27

ex

190

110,49

vi

Command not found command order, when using command synonyms (alias) command syntax

12,

-ms

commands, arrows commands, formatting commands, one-way commands, two-way comments from others

common

15

475 161

277 92 14

110 111

14,111 175

English words,

list

363

compact a file compact compare two files

276 277 361

compatibility, /zro^and

macros

144

conceptual overview

105

251

control characters, nroff

345

66 428

control characters. Shell

49, 66

66 49, 131

conventions used copy a file

in

16

48

CO/7V, in

check diction .check for format errors

163

check for eqn errors

467 89, 187

467 163

263

book

copy text, in editor Core dump corrections, in Shell

230 465 49 89

checkeq checknr Cheetos

112

361

change line change password change word changing text

check spelling

interpreters

comm

251

characters on screen, weird

command command command

95

131

change directory

character location, with eqn

423 305

241

cd

cb

136

columns, in tables combining files combining Shell commands

123

cc

cat

commands

communicating with others

485 475 87, 304 230 49, 130

Cannot open filename

clean up script, sample

439 325 319 439 153, 395 207 457 307 343

4

370 414 218 279 279

citations, in papers

clear

475 343

buffers,

chmod

2

broken pipe

buffer and disk

287, 294

clear screen

153

BSD UNIX

-iv

3

break page, nroff .br

chkps

editor

cp

3

84, 304

136

476 17

137

84

creating directories

172

cryogenics, microprocessor

crypt

292 275

CTRL-B

126 126, 281

CTRL-F CTRL-H CTRL-S CTRF-U

126 17 15

126

519

267

(.), in Shell

CTRL-V

225

dot

CTRL-VV

225

dot, in editor

CTRL-Z

293

dot-dot

.Ct

330

double backslash double spacing text

41

cursor

.), in

(.

208 268 341

Shell

71

45

122

dw

cursor skips lines

480

e

123

cursor, absent

471

echo

customizing your account

171

edit

cut and paste, in editor

133

279 282 236

cursor

moving commands

48

CH data base

management

data placement in table

486 429 15

date

230 44

db dd default values, nroff'

74

defaults, in Shell

93

environment, setting editing environment editing,

39

file recall

editor, line

217 177

electronic mail

242

end of file marker end of line, character end of word, character environment, editing

281

editor scripts

323 320

.EN

330 425

eqn output eqn with other pre-processors

definitions, string

159

equations, examples

delete a character delete lines

46 44

delete text

139

defaults, changing troff -ms defaults, rro#requests

define a

macro

defining a

TAB

delete words

deleted text, oops! deleted text, recall of

DELETE key delim, in eqn derofT .de

marks diagnosing problems

diacritical

45

478 233 64, 96, 291

449 356 330 450 469

206 206 236 447 445 466 466 459 172, 447 447 447

eqn

equations, formatting equations, in

files

.EQ

175

errors in formatting, check

467 26, 50

errors in eqn^ check

ESCAPE key escape character, nroff

341

executable

367 370 384 428

files

execute permission exit, from wro^formatting

expanding experience

.

a table

53

file

diction check

89

exponents, with eqn

455

diction

89

ex editor

177

250 257

.ex

384

cjcand

vi,

moving between

251

^-jcand

vv;

relationship

directories directories within directories

directory,

change

directory, lost within directory,

make

directory, parent

477 172, 250 269

191

fg

293

338 116

Eg macro

disk and buffer

106

file

descriptors

126, 227

file

length,

displays, with eqn

461

file

permissions

dollar sign, in editor

139

file

relocation

dot {nroff conixoX character)

345 283

file,

(.) files

520

195

Mode ex Command Mode

179

dot

5

189

ex Append

disk display adjustment

editors

file,

maximum

permanent copy temporary copy

190

troff

322 368, 378 250 106

106

filemodes

370 370 40 274, 306 40

filemodes, change

filename filename expansion character filename, misspelled

home-made macros horizontal lines, in tables

Houdini Award

329 440 32



50 129

1

I

filenames, examples

83

ignoreeof

281

filenames, rules on

82

improved editing indent, temporary

174

as sections of larger paper

files,

filled text

172 72, 343

filling

72

find

266, 286

find a lost

266

file

72

.fi

font change, tables

index, create index, formatting

management) macro use

Ingres (data base initializing for

input characters, translate

font changes, text

442 319

input, standard

font characters

321

insert text, in editor

font selection, with eqn

interactive

font. Italics

464 318 318 317

interpreters,

footer margin, change

159

.IP

footnotes, formatting

415

ISP

foreground

293

Italics

font, ^old font,

form

Roman

a process

382 68, 152 110

letters

format a file format commands format commands, conventions format commands, remove format errors, check formatted output, absent formatted output, with macros formatting formatting, volunteer with .fo

fractions, with eqn .ft

B

.ft

I

.ft

R

function keys g (in

editor)

G global search

Greek

letters

grep halt scrolling

65

356 163, 175

input

jobs joining

files

justified text

295 338 112

486

72

kill

292

killing a process

292 239 209 139 234 457

Kryptonite last line in file

lettered buffers limits, with

eqn ex

190

line addresses, rules

137

line addresses, in

ex

177, 189

numbers,

69 179

line editor, line length line

in editor

215 125

line print a file

68

line printer

210 451 273

line spacing

30 70

16

lines in boxes, tables listing files

login

87

440 30 69

.11

430

directory

115

317 394 293 303

invisible character

headings,

Home

package)

font

locating

.he

nroff

command

(statistical

159

head

interpreters

146

header margin, change in tables

memory,

152

42

50, 129

interactive processing

Kirk, Captain

macros 152 347 456 318 317 318

360 116

command

473 64

158

76

file

internal

66 172, 363 403 486

words or phrases

login banner, absent

347

.login file

250

logout

273 10

472 284 12

521

.logout

287

file

15

look

384 265

looping, in nrqtf' lost files, find

30, 68

Ipr

145

.LP

30, 253

Is

70

.Is

macro arguments macro calls macro definitions macro examples, paragraphs macro file, creating macro, define a

macros macros, arguments within macros, create your own

337 144, 328 330 145

332 330 144, 328 337

251

mkdir Module use more move

move

3

86 139 85

a file

195

moving between ex and vi moving cursor backward moving cursor forward moving text across files moving text, within a file moving the cursor Mrs. Zak

123

122 173 138, 173

122

88 142

-ms macros -ms macros, how read multi-columned tables multiple authors, refer

333 432

408 382

.

175

multiple copies of letters

home-made macros, how work

329 332

mv

85

n {next)

43

macros, with moff' Mail

155

naming macros

242

.na

accessing

242

needs

153

reading

243

neqn

244 243 245 250

neqn .ne

445 447 154

.nf

72

macros,

Mail Mail Mail Mail Mail

make

sending a

file

sending a note using

vi

with

a directory

man

98

management, account manual access

272 98

map

238

.NH

149

no break, in nrojf no fill, in nroff

345 71

476 281, 305

No match noclobber .nr

FM

159

12

.nr

HM

159

12

.nr

LL

157

A

8

.nr

PO

157

B

22

.nr

PS

C

40

.nr

VS

D

102

nroff'

E

200 473 226 308 308 463 322 227 475 204 292 407

nroff'dind

324 325 64 144 338 310 142, 327 338

margin, deviating

marking a position while editing matching a single character matching characters matrices, with eqn

maximum

file

length,

troff'

mb

(mark position 8) messages on screen meta characters, editor microprocessor cryogenics mistakes, refer

522

72

12

maps, arrows maps, boxes maps, symbols

Map Map Map Map Map

332

A7

macro compatibility

ro#internal

nroff' O'pXxons

nroff requests

memory

number registers number registers, changing values number registers, resetting 323, number registers, troff -ms numbered buffers numbered headings numbered text numbers in editing environment

157

156

324 233 149 136

282

384

.nx

Permission denied

0

51

permissions

O

51

petes

objectives of

book

2

73

offset output

one-way text change commands one-way commands 69, open a line above open a line below

129 73, 111

51, 71 51

231

operators, text

options

93

orphans

176

89

output, redirect

field

dilemma

phototypesetting

itrqff)

PID number piles,

with eqn

476 369 484 312 292 462

pipe reroute

95

pipe

64

place text in a buffer

placement of data

in table

.pi

point size point size changes

235

429 70, 154, 346 314 316 314 315 315 442 464

output, standard

116

point size, available on troff

output, troff

322

point size, default

overview, conceptual

105

point size, specifying

p (in

134

point size, tables

134

point size, with eqn

p (in ex)

215-

.po

pack

276 277 320

.PP

145

previewing a formatted paper

176

153

print

P

(in

vi) vi)

a file

pack page characteristics, page control

troff

page length

70, 154, 346

page length, /7ro//'’problems

page paragraph macro examples paragraph macros paragraph reset macro paragraph resets, with troff-m

70

73

print offset

73

working directory

265

printer selection

176

printing files

30 469

64, 86

problems, diagnosing

145

problems, formatting

144

469 469 470 470

paragraph, block {nrqff) paragraph, exdented

148

paragraph, indented

146

problems logging in problems. Shell or editor problems, unknown origin process status check process, background a process, foreground a

paragraph, labeled

146

process,

paragraph,

145

process, stop

292

148

processing, batch

295

66, 145

processing, interactive

295

parens, with eqn

457

Programmer’s Manual

98, 379

parent directory

269

and wholes passwd password password, change

301

programming in C prompt fields, in refer

485 407

path, search

375

ps

291

pathnames pathnames, copying pathnames, editing

258

.ps

316

261

put text

134

pwd .PX

265

pattern scanning

260 483

401

pattern searches

174

:q!

107

patterns vs. words, in editor

205

Q

195

permanent copy of

106

left

block

paragraph, quote paragraph, standard

parts

351

323 67

10 16

prompts,

files

file

Qe

in refer

90, 289

293 96, 292

kill

prompt. Shell prompts, change

16

291

11 in refer

411, 412

405

335

523

351

QP

148

.RT

.Qs

334

R LI BOUT key

quality of formatted output

172

ruined a

quit an editing session

107

S

quit editing without writing

181

s (in

Quote paragraph macro r

.rd

read

command

read text into current

file

read permission reassembly of files

334 46 383 383 186, 303 370

S

(statistical

48, 130

130

(in vi)

sample bibliography sample paper, formatted sample paper, input file save a

recall stored text

234 234

script file

redundant

lines,

remove

refer

refer refer,

formatting

refer,

printing

refer,

with other pre-processors

.

reminder

file

remove a batch job remove a file remove formatting commands remove magic, in editor remove spaces, in editor rename a file repeated characters,

in editor

replace a character Request, while logging in

360 404 415 410 410 416 283 298 85

356 209 216 85

209 46 9

327

requests, nroff

79 108

screen, clear

89, 117

80

file

233

redirect output

215 417

s (in ex)

recall deleted text

text

486

package)

vi)

scrambling

yanked

107

file

176

recall

64, 96

275 279

a file

script, clean

296 218

up

87, 127

scroll text

scrolling, stop

16

search buffers

234

search

command

43

search path

375

search path, setting

377

searches, excluding characters

208 174

searches, pattern searches, upper/lower case letters

207 207

section headings

149

searches, range of characters

sed (stream editor)

semicolon separating a

file

set :set all :set

ignorecase

482 96 302 280, 376 236 238

set ignoreeof

281

:set list

413

351

set noclobber

281

-ms macros

156

:set nolist

413

number

156

:set

resetting terminal type

480

:set

return to Shell, from ex

197

setenv

reroute, with pipe reset

95

macro, paragraph

resets,

resetting

registers

return to Shell, from

RETURN

key

rni

robin rotfbib

Roman

font

root

rows,

.RP .RS .RE

524

in tables

vi

nonumber number

EXINIT

27

setting a trap,

13

setting an editing option

85

setting your search path

macros

236 136, 179, 282 282 348 237 378

299 410

Shell

commands, combining

Shell

Mode

318 374

Shell

programming

Shell variables

281

423

.SH

149

398 342 342

single spacing text

70

slash-search

43

sort a

file

95 13, 81, 109

484

357

sort

357 410 335 286 335 65

sortbib

source

in a file

source .login .so

.sp

space down,

in

moff

spacing, with eqn

spanning entries

in tables

special characters.

Append Mode

special characters, editor special characters, in searches

65

452 431, 437 224 204 215

tables,

tables,

multi-columned spanned entries

TAB tail

432 431, 437 key 88

tbl

421

tbi

427 402 426

.TC .TE temporary copy of temporary indent Term type

file

106

66 11

terminal

11

special formatting tasks

174

terminal display of underlining

331

special rroy^'characters

321

terminal locations

247

specifying terminal type

41

terminal type, specifying

41

spelling check

89, 187

terminal, switch on

8

spell

88, 187

terminate a process

96

Spock, Mr.

239

text addresses

standard input

116

text blocks,

star (*) character, in Shell

308

text blocks, tables

Star Trek Addicts

239 486

change commands, one-way 129 text change commands, two-way 132 text changing commands 128, 229 text missing 474 text not filled 474

statistical

packages

stop scrolling

16

Stopped jobs stopping a process storage buffers, text

strange characters

stream editor

476 292 232 471, 479 482

232

form

letters

text

text operators

231

text storage buffers

232 66

.ti

string definitions

159

tilde (')

sub-directories

250 297 455 48

time share system

title

page, with nroff

130

title

page, with nroff -ms

submitting a batch job subscripts, with eqn

substitute a character

substitution

commands

title

252 41

lines

title lines,

substitution,

all

lines

213

titles, refer

substitution,

all

occurrences

213

.tl

substitution, current line

211

.TL

substitution, next occurrence

212

tmac. s

substitution, specified line

211

tr

346 header

&

footer

suggestions, typing

24

translate input characters

suggest

90

trap, setting

switch, on terminal

symbols, available with eqn syntax,

command

system crash

.T&

(in table)

tab(

+)

(in table)

table formatting table headings table of contents, formatting

8

trqff

450

trqff

92

388 435

-ms rrq/7'maximum

file

length

159 172, 393

393 408 346

398 352 360 360 348 312 312, 322 322 322 320

472 435 425

/rq//’output

//qZ/special characters

321

172

troubleshooting

468 424

430 172, 399

r/'q/f

request defaults

.TS two-headed arrows. Maps

42

525

!

two-way commands

42, 111, 132

u

314 317 24 44

U

140

ucb bin

315

type characteristics, determining type font typing suggestions

.ul

67

unadjusted text

72

111

uncompact

67

underline text

474 325 319

underlining, problems underlining, trojf'-ms

underlining, troff

44, 140

undo changes

.vs

317

:w

108

:w

command, forms

of

122, 303

291

wait weird characters on screen

49

wh who

348

widows word salad, display word salad, file

176



14

479 478 246

write write material into a

file

370 486

^rite permission

Workbench

Writers’

writing a

184, 185

108

file

71

writing for safety

182

uniq unique lines, locate UNIX Version 7

360

writing onto disk

108

361

writing out text

302

unpack

277

unfilled text

4

using the Modules

3

374 172, 355 440 317

usr bin utility

programs

vertical lines, in tables vertical spacing

23, 196

vi vi

Append Mode

110

V/

Command Mode

no

v4

with refer

408 86

view a file view end of file only view entire file view top of

file

visual editor,

commands

to enter

volunteer formatting, with -ms

526

writing,

UNIX

advance work

75 171

writing, grinding-it-out

173

writing, production issues

175

:wq!

108

X (in

vi)

46

.XA

400

.XE .XP .XS

401

X out

148

400 46 134

86

yank text yanked text, recall You have Mail.

234 242

87

yy

134

224

\

134

152

z#.

127, 227

ZZ

27, 107

88

only

writing process, with

QUICK ACCESS CHART

Add

Character

Word

Line

24, 129

24, 129

24, 129

a

i

A

I

O

0

a

47, 231

Change

Delete

Find

A

I

O

0

a

i

a

S

cc

229, 231

136, 229

yw

yy, :4co 6

24, 129

24, 129

i

A

I

0

O

a

i

A

I

0

44, 231

X

dw

dd

15

43

125

word

64G

/

24, 129 I

0

49, 231

24, 129 i

O

24, 129, 194

I

I

i

133

Join

J 231

Move

dw & p

Remove Substitute

Note: Page

0

45, 230

i

*

A

I

46

lb

Insert

O

0

cw

24, 129 i

A

1

48, 231

Copy

a

i

s

r

Create

*

46 X

45, 230

48, 130

48, 231

s

cw

number appears

in

139, 231

&

dd

command (s)

:

6 ni

33

44, 231

dw

top row;

n,

dd, :6 49, 130 cc

appears

in

S

bottom row.

527

Paragraph

File

Directory

24, 129

23, 191

172, 250

a

A

I

i

0

O

27, 107

49, 231

ZZ &

6S

7cc

ex

vi

6co

i

I

A

cd

24, 191

0

0

vi

ex

44

85

6dd

rm

226

266, 286 find

11

Add Change

Copy

cp

9

24, 129 a

250

84

136 Jyy, :4,

vi

mkdir

172, 251

mkdir 493 rmdir

Create

Delete

Find

Insert 87, 304

Join

cat

85

139, 231

6dd

&

p, :i,

5

85

6dd, :2,5d

rm

dec

6S

Move

mv

44, 139

49, 130

528

6m

493 rmdir

Remove Substitute

Map A

@ 3 O BC O Station 2

Shell (# $ Station 3

Mode

% &

or

Prompt)

^'^orcj

Station 4

ype

B Map

C Map

}

f

-n

amicuPftWOLO'sxsQmcEliW CENTER v^ MEDiCWSIRECT Tiso CieMENl 94121 cA.M cR^^iClSCO. CA

/M .asUS'l

PATHOLOGY SERVICE (USA) VA MEDICAL CENTER 4153 CLEMENT STREET StCi FRANCISCO, CA 94121

ClITllCAL

unixforpeoplemodOObao .n,x.orpeoplemodOOb,rn

nonintimidating “hands-on” guide to the UNIX Operating System that assumes no previous experience with UNIX or computing in general. Beginning programming stCidents and people in business and Industry

A

use UNIX through a systematic, step-by-step, at-the-termlnal Introduction to the various resources available on the UNIX system. Spiral binding, larger type, extensive field testing, and a tutorial format make this book easy to use and understand. learn to

SPECIAL FEATURES: •

Procedural Approach. Each concept

is

introduced with a “doing”

activity.

• •

Learning Objectives and Procedures. Clearly stated. Friendly Style. Directed to people with a variety of experiences, educational levels, and occupations.





Conceptual Maps. Visual representations of the system make the material easier to comprehend.

Sequencing of

Activities.

A method

that

Is

crucial in this kind of

book.

Also of interest: Illustrations (drawings and photographs) reinforce concepts and demonstrate actions.

a

PRENTICE-HALL,

INC.,

Englewood

Cliffs, N.J.

07632

ISBN 0-13-13?MS'f-0