GIT ICS 80 03_Software_Tools_Subsystem_Users_Guide_2ed_Apr80 03 Software Tools Subsystem Users Guide 2ed Apr80

GIT-ICS-80-03_Software_Tools_Subsystem_Users_Guide_2ed_Apr80 GIT-ICS-80-03_Software_Tools_Subsystem_Users_Guide_2ed_Apr80

User Manual: GIT-ICS-80-03_Software_Tools_Subsystem_Users_Guide_2ed_Apr80

Open the PDF directly: View PDF PDF.
Page Count: 197

DownloadGIT-ICS-80-03_Software_Tools_Subsystem_Users_Guide_2ed_Apr80 GIT-ICS-80-03 Software Tools Subsystem Users Guide 2ed Apr80
Open PDF In BrowserView PDF
GIT-ICS-80/03
SOFTWARE TOOLS SUBSYSTEM
USER'S GUIDE
2ND EDITION
APRIL,

School
Information

1980

of

and Computer Science

GEORGIA INSTITUTE
OF TECHNOLOGY

6IT-ICS-80/03
SOFTWARE TOOLS SUBSYSTEM
USER'S 6UIDE
2ND EDITION
APRIL,

1980

T. Allen Akin
Perry B. Flinn
Daniel H. Forsyth, Jr.

School of Information and Computer Science
Georgia Institute of Technology
Atlanta, Georgia 30332

INTRODUCTION TO THE
GEORGIA TECH SOFTWARE TOOLS SUBSYSTEM USER'S GUIDE
The documents following this Introduction comprise the most recent version of the User's
Guide for the Georgia Tech Software Tools Subsystem for Prime 350 and larger computers.
This
Guide brings together in one place all the tutorial and reference information useful to
novice and intermediate users of the Subsystem.
It deals with several important aspects of
Subsystem use: the user interface in general, unavoidable aspects of the underlying operating system, and the most-frequently used major commands.
Each topic is covered in a separate
document (available individually) and all documents are collected together with this
Introduction to form the Guide itself.
Experienced users, as well as beginning users who
wish to expand their knowledge of the Subsystem, will find the Software Tools Subsystem
Reference Manual valuable.
The development of the Georgia Tech Software Tools Subsystem was originally motivated by
the text Software Tools by Brian W. Kernighan and P. J. Plauger, Addison-Wesley, 1976. That
text is still the basic reference for the tools that it covers, particularly Ratfor, the text
editor, the macro preproces.or, and the text formatter.
SOFTWARE TOOLS SUBSYSTEM TUTORIAL

l1li

USER'S GUIDE TO THE PRIMOS FILE SYSTEM

1l1li

INTRODUCTION TO THE SOFTWARE TOOLS SUBSYSTEM TEXT EDITOR

l1li

USER'S GUIDE FOR THE SOFTWARE TOOLS SUBSySTEM COMMAND INTERPRETER

l1li

USER'S GUIDE TO THE RATFOR PREPROCESSOR

l1li

SOFTWARE TOOLS TEXT FORMATTER USER'S GUIDE

l1li

Copyright (cl 1978, 1979, 1980 Georgia Institute of Technology

Software Tools Subsystem Tutorial

•
T. A11en Akin
Perry B. Flinn
Daniel H. Forsyth, Jr.

School of Information and Computer Science
Georgia Institute of Technology
Atlanta, Georgia 30332
April, 1980

TABLE OF CONTENTS

Introduction ••••••.••••••.••.••••••••••••••••••••••••.•••••••••••••••••••••••••••.•.•
Getting Started •••••••••••••••.•••••••••••••••••••••.•••••••••••••••••••••••••••••
Correcting Typographical Errors...................................................
Adjusting to Terminal Characteristics •••••••••••••••••••••••••••••••••••••••••••••
Finishing Up •••••.••••.••.••••••••••.•••••••••••••••••••.••••••••.••••••••••••••••

3
3
4
4
5

Online Documentation •••••.•.•••••••••••••••.••••••••••••••••••••.••••••••••••••••••••
The 'Help' Command ••••••.•••••••••••••••••••••••••.••••••••••.••••••••..••••••••••
The 'Usage' Command •••••••••••••••••.••••••••••••••••••••••••.•••.•.••••••••••••••

7
7
8

Ut iIi ty Commands ••••.•.••••••••••••••••••.•••••••••••.•••••••••••••.••••••••••••.••••
The 'Lf' Command ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Th e 'Ca t' Command •••••••••.••••••••••••.••••••••••••••••.•••••••••••••••••••..••..
Deleting Files ••••••••••••••••••.••••.••••••••••••••.••••••••••••.••.•••••••••••••
The Subsystem Postal Service......................................................
The Subsystem News Service ••••••••••••.•••••••••••••••••••••••••••••••••••.•••••••

9
9
10
11
11
11

Input/Output •••••.•••••••••••••••••.•••••.•••••••••••..•..•••••••••••.•••••••••••..••
Standard Input and Standard Output ••••.••••••••••.••••••••••••••.•••••••••••••••••
I/O Redirection...................................................................
Examples of Redirected I/O Using 'Cat' .•.•.•••••••.•.•.•.••••••••••.••••••••••••••

13
13
13
13

Using Primos from the Subsystem .......................................................
Executing Primos Commands from the Subsystem •••••.••••••.••••••••.••••••••••••••••
Using ~rtran from the Subsystem ••••••••••••••••.•••••••••••••••••••••••••••••••••
Using the Linking Loader from the Subsystem •••••••••.•••.••••.••••••.••••..•..••••
Warning ••••••••••••••••••••.••••••••.•••••••••••••••••••.•••••••••••••••••••••••••

15
15
15
16
16

Program Development ••••••.••••.••••••••••••••••••••••••••••••••••••••••••••••.•••••••
Caveats for Subsystem Programmers ••••••••.••••••••••••••••.••••••••••••.••.••.••••
The Subsystem Text Editor.............................. •.••••••••••••••••...••.••••
Creating a Program ••••.•••••••••••••••••••••••••••••.•••••••••••••••••••••••••••••

17
17
17
18

Advanced Techniques ••••••.•••••••••••••••.•••••••••••••••••..••••••••••••••••••••••••
Command F i l e s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Pipes •••••••••••••••••••••••••••••••.•••••••••••••••••••••••••••.••••••••.••••••••
Additional I/O Redirectors •.••••••••.•.••••••••••••••••••••••••.••••••••••••••••••

22
22
22
22

Background ••••••••••••••••••••••••••••••••••••••.••.•••••••••••••••••••••••••••••••••
Ancient History...................................................................
Authors and Origins •••••••••••••••••••••••••••••••••.•••••••••••••••••••••••••••••

24
24
25

~

1 -

Foreword
The Software Tools Subsystem is powerful collection of program development and text
processing tools developed at the Georgia Tech School of Information and Computer Science,
for use on Prime 350 and larger computer systems. The tutorial that you are now reading is
intended to serve as your first introduction to the Subsystem and its many capabilities. The
information contained herein applies to Version 7 of the Subsystem as released in April 1980.

- 2 -

Software Tools Subsystem Tutorial
Introduction
The Software Tools Subsystem is a programming system based on the book
Software Tools, by Brian W. Kernighan and P. J. Plauger, (Addison-Wesley Publishing
Company, 1976), that runs under the Primos operating system on Prime 350 and larger
computers.
It
allows
much greater flexibility in command structure and
input/output capabilities than Primos, at some small added expense in processing
time.
This tutorial is intended to provide sufficient information for a beginning
user to get sta~ted with the Subsystem, and to acquaint him with its basic
features;
it 1S by no means a comprehensive reference. Readers desiring a more
detailed exposition of the Subsystem's capabilities are referred to the Software
Tools Subsystem Reference Manual Qnd to the remainder of the Software Tools
suosystem User's GUlde, of WhlCh this Tutorial is a part.

Getting Started
Since the Subsystem 1's composed entirely of ordinary user-state programs, as opposed
being a part of the operating system, it must be called when needed.
The following example shows how a typical terminal session might begin.
the user are boldfaced.
OK, login login name
Password:
LOGIN NAME (15) LOGGED IN AT 9:22 010578
OK, swt
Password:
]

to

Items typed by

(1 )

(2)
(3 )
(4)
(5 )
(6)

(1 )

A terminal session is initiated when you type the Primos 'login'
command.
"Log i n name" here represents the login name that you were assigned when your
account was established.

(2)

Primos asks you to enter your login password (if you have one) and turns off the
terminal's printer. You then type your password (which is not echoed) followed by
a newline.
(Note: password checking on login is a feature of Georgia Tech Primos;
at other installations, this line will be omitted.)

(3)

Primos acknowledges a successful login by typing your login name, your process number (in parentheses), and the current time and date.

(4 )

Primos indicates it is ready to accept commands by typing "OK,".
this prompt, Primos is waiting for you to type a command.)
n.§.oft~are '!.ools") to start up the Subsystem.

(5)

'Swt'
prompts you for your Subsystem password.
This password will have been
assigned to you by your Subsystem Manager at the time he created your Subsystem
account.
(Note:
Under Georgia Tech Primos, Subsystem passwords are never issued,
nor prompted for by 'swt'.) After you receive the prompt, enter your Subsystem
password.
It will not be printed on the terminal.

(6)

The Subsystem's command interpreter prompts with "l", indicating that it is ready
to accept commands.

(Whenever you see
Type
'swt'
(for

When the Subsystem command interpreter has told you it is waiting for something to do
(by typing the "]"), you may proceed to enter commands. Each command consists of a 'commandname', followed by zero or more 'arguments', all separated from each other by blanks:
command-name

argument

argument

The command name is necessary so that the command interpreter knows what it is you want it to
do.
On
the other hand, the arguments, with a few exceptions, are completely ignored by the
command interpreter. They consist of arbitrary sequences of characters which are made
available to the command when it is invoked.
For this reason, the things that you can type
as arguments depend on what command you are invoking.
When you have finished typing a command, you inform the command interpreter of this
hitting the "newline" key.
(On some terminals, this key is labeled "return", or ncr".
both the "newline" and "return" keys are present, you should use "return".)

- 3 -

by
If

Software Tools Subsystem Tutorial
Incidentally, if you get some strange results from including any of the characters

>
within a command name or argument, don't fret.
These are called "meta-characters" and each
has a special meaning to the command interpreter. We will explain some of them later on.
For a more complete description of their meaning, see the User's Guide for the Software Tools
Subsystem Command Interpreter.
Correcting Typographical Errors
If you are a perfect typist, you can probably skip this part. But, if you are like most
of us, you will make at least a few typos in the course of a session and will need to· know
how to correct them.
There are three special characters used in making corrections. The "erase" character
causes the last character typed on the line to be deleted.
If you want to delete the last
three characters you have typed so far, you should type the erase character three times.
If
you have messed up a line so badly that it is beyond repair, you can throwaway everything
you have typed on that line in one fell swoop by typing the "kill" character. The result
will be that two backslashes ( ) are printed, and the cursor or carriage is repositioned to
the beginning of the line. Finally, the "retype" character retypes the present line, so you
can see exactly what erasures and changes have been made.
You may then continue to edit the
line, or enter it by striking the return key.
When you log into the Subsystem for the very first time, your erase, kill and retype
characters are control-h (backspace), DEL (RUBOUT on some terminals), and control-r, respectively.
You can, however, change their values to anything you wish, and the new settings
will be remembered from session to session. The 'ek' command is used to set erase and kill
characters:
ek erase kill
"Erase" should be replaced by any single character or by an ASCII mnemonic (like "BS" or
"SUB"). The indicated character will be used as the new erase character. Similarly, "kill"
should be replaced by a character or mnemonic to be used as the new kill character. For
instance, if you want to change your erase and kill characters back to the default values of
"BS" and "DEL", you can use the following command:
ek BS DEL

(By the way, we recommend that you do not use "e" or "k" for your erase or kill character.
If you do, you will be hard pressed to-Change them ever again!)
Adjusting to Terminal Characteristics
Unfortunately, not all terminals have full upper/lower case capability.
In particular,
In the belief that
most of the older Teletype modelS can handle only the upper case letters.
the use of "good" terminals should not be restricted by the limitations of the "bad" ones,
the Subsystem preserves the distinction between upper and lower case letters.
To allow users of upper-ease-only terminals to cope with programs that expect lower case
input, the 'term' command provides case conversion facilities:
term -nolcase
This command instructs the Subsystem to force all subsequent upper case letters you type
to be converted to lower case, and all lower case letters sent to your terminal by the computer to be converted to upper case.
In short, it means "I have no lower-case."
To provide further assistance to users whose terminals have a limited character set,
this command also activates a set of "escape" conventions to allow them to enter other
special characters not on their keyboard,
and to provide for their printing. When the
"escape" character (@) precedes another, the two characters together are recognized by the
Subsystem as a single character according to the following list:
@A

->

A

@Z
@(
@)

->
->
->
->
->

Z

@

@'

(note that

A -> a in " nolcase" mode)

{
}

-

4

-

Software Tools Subsystem Tutorial

@!

->

All other characters are mapped to themselves when escaped; thus, "@_" is recognized as H@_H.
If you must enter a l i teral escape character, you must enter two: n@@" .
If you have given a "term -nolcase" command you must use escapes to enter upper case
letters, since everything would otherwise be forced to lower case.
For example,
@A
is used to transmit an upper case 'A', while
A

is used to transmit a lower case 'A'.
All output generated when the "-nolcase" option is in effect is forced to upper case for
compatibility with upper-ease-only terminals.
However, the distinction between upper and
lower case is preserved by prefixing each letter that was originally upper case with an
escape character. The same is true for the special characters in the above list. Thus,
Software Tools Subsystem
would be printed as
@SoFTWARE @TooLS @SUBSYSTEM
under the n-nolcase" option.
Finishing Up
When you're finished using the Subsystem, you have several options for getting out. The
We
first three simply terminate the Subsystem, leaving you face to face with bare Primos.
cover them here only for the sake of completeness, and on the off chance that you will
actually want to use Primos by itself.
First, you may type
stop
OK,
which effects an orderly exit from the Subsystem's command interpreter and gives control to
Primos'
command interpreter.
You will be immediately greeted with "oK,n, indicating that
Primos is ready to heed your call.
Second, you may enter a control-c (hold the "control" key down, then type the letter
ncn)
immediately after the "] II prompt from the command interpreter. TAKE HEED that this is
the standard method of generating an end-of-file signal to a program that is trying to read
from the terminal and is widely used throughout the Subsystem. Upon seeing this end-of-file
signal, the command interpreter assumes you are finished and automatically invokes the 'stop'
command.
The third and least desirable meth01 is to type a control-p or BREAK.
This
any running program, including the command interpreter, and (with few exceptions)
Primos. This last method is definitely not the method of choice, since it is
interrupt the Subsystem at an inconvenient point, causing things to be left in
chaos. You are strongly encouraged to choose either of the first two methods over
Finally, we come to the method you will probably want to use most often.
mand simply ends your terminal session and disconnects you from the computer.
example illustrates its use.
(Once again, user input is boldfaced.)
] bye
LOGIN NAME (15) LOGGED OUT AT 10:16 010578
TIME USED= 0:25 10:39 1:33
OK,

(1)
(2)
(3 )
(4)

(1)

You type the 'bye' command to end your terminal session.

(2)

Primos acknowledges, printing the time of logout.

(3)

Primos prints a summary of times used.

- 5 -

interrupts
returns to
likely to
a state of
this one.

The 'bye' comThe following

Software Tools Subsystem Tutorial
The first time is the number of hours and minutes of connect time.
The second time is the number of minutes and seconds of CPU time.
The third time is the number of minutes and seconds spent doing disk i/o.
(4)

Primos signals it is ready for a new login.

- 6 -

.

Software Tools Subsystem Tutorial
Online Documentation
Users, old and new alike, often find that their memories need jogging on the
use of a particular command. It is convenient, rather than having to look something up in a book or a manual, to have the computer tell you what you want to know.
Two Subsystem commands, 'help' and 'usage,' attempt to address this need.

The 'Help' Command
The 'help' command is designed to give a comprehensive description of the command in
question. The information provided includes the following: a brief, one-line description of
what the command does; the date of the last modification to the documentation; the usage
syntax for the command (what you must type to make it do what you want it to do); a detailed
description of the command's features; a few examples; a list of files referenced by the command; a list of the possible messages issued by the command; a list of the command's known
bugs or shortcommings; and a cross reference of related commands or documentation.
'Help' is called in the following manner:
help command-l command-2 •••
If help is available for the specified commands, it is printed; otherwise, 'help'
that no information is available.

tells

you

'Help' will only print out about as many lines as will fit on most CRT screens, and then
prompt you with the message "more?". This allows you to read the information before it rolls
off the screen, and also lets you stop getting the information for a command if you find
you're not really interested. To stop the output, just type an nn" or a "q" followed by a
NEWLINE. To continue, you may type anything else, including just a NEWLINE.
Several special cases are of interest. One, the command "help" with no arguments is the
same as "help general", which gives general information on the Subsystem and explains how to
use the help command. Two, the command "help -in produces an index of all commands supported
under the Subsystem, along with a short description of each. Finally, "help bnf" gives an
explanation of the conventions used in the documentation to describe command syntax.
Examples of the use of 'help':
help
help
help
help
help

(1)
(2)

-i
rp ed term
bnf
guide

(3 )
(4 )
(5)

(1)

General information pertaining to the Subsystem, along with an explanation of the
'help' command, is listed on the terminal.

(2)

A list of currently supported commands and subprograms, each with a short
tion, is listed on the terminal.

(3)

Information on the Ratfor preprocessor, the Software Tools text editor, and the
terminal configuration program is printed on the terminal.

(4)

A description of the notational conventions used
printed.

(5)

Information on how to obtain the Subsystem USer's Guides is listed on the terminal.

to

describe

command

descrip-

syntax

is

Since beginning users frequently find printed documentation helpful, you may find the following procedure useful. Unfortunately, it involves many concepts not yet discussed, so it will
be l'ather cryptic; nevertheless, it will allow you to produce a neatly-formatted copy of output from 'help'.

1 help -p I os >/dev/lps/f
1 help -p rp se term I os >/dev/lps/f
1 help -p -i I os >/dev/lps/f

I
I
I

(1 )

(2)
(3 )

(1)

The general information entry is printed on the line printer.

(2)

Information on the Ratfor preprocessor, the screen editor, and the terminal configuration program is printed on the line printer.

- 7 -

Software Tools Subsystem Tutorial
(3)

The index of available commands and subprograms is printed on the line printer.

The 'Usage' Command
Whereas 'help' produces a fairly comprehensive description of the command in question,
the 'usage' command gives only a brief summary of the syntax of the command. The syntax is
expressed in a notation known as Backus-Naur Form (BNF for short) which is itself explained
by typing "help bnf".
The
'usage' command
examples illustrate.

is

used

in the same way as the 'help' command, as the following

1 usage usage

(1 )
(2)

1 usage fmt help
(1)

The syntax of the 'usage' command is printed.

(2)

Usage information on the Software Tools text formatter and the
printed.

- 8 -

'help'

command

is

Software Tools Subsystem Tutorial
Utility Com.ands
The Subsystem supports several utility commands of general interest. These
commands have proven to be important in daily use, and so have been given a
separate section in this tutorial. Each will be discussed in turn.

The 'Lf' Command
The
'If'
(for "list files") command is the preferred method for obtaining information
about files.
Used by itself-without any arguments, 'If' prints the names of all the files in
your current directory in a mUlti-column format. This, however, is by no means all that 'If'
can do.
In fact, used in its general form. an 'If' command looks something like this:
. If

options

files

The "files" part is simply a list of files and/or directories that you want information
about.
If the "files" part" is omitted, 'If' assumes you mean the current directory.
For
each file in the list, information about that file is printedi for each directory listed,
information about each file within that directory is printed.
The "options" part of the command controls what information is to be printed. It is
composed of a dash ("-") followed by a string of single character option specifiers. Some of
the more useful options are the following:
c

print information in a single column format.

d

for each directory in the list,
instead of about its contents.

1

print all known information about the named files.

w

print the size (in 16-bit words) of each named file.

print

information

about

the

directory

(As
always,
if you would like complete information on 'If', just use 'help'.)
above, if no options are given, then only the names of the files are printed.

itself

As we said

Here are some examples of 'If' commands:
If

(1)

I f -1

(2 )

I f //lkj

(3)

If -cw //lkj =extra=/news

(4)

(1)

List the names of all files in the current directory, in a multi-column format.

(2)

List the names of all files in the current
that is known about each file.

(3)

List the names of all files in the directory named "lkj".

(4)

List the names and sizes of lkj's files in a single-column format, followed by the
names and sizes of all files in directory "=extra=/news".

directory,

including

all

information

Before discussing filename specifications, a short overview of the Primos file system is
needed •.
Primos files are stored on several disk packs, each with a unique name.
Each pack
contains a master file directory (mfd), which contains a pointer to each primary directory on
that disk.
Each of these primary directories (one for each user, and several special ones
for the system) may contain sub-directories, which may themselves contain further subdirectories, ad infinitum. Any directory may also contain ordinary files of text, data, or
program code.
The Software Tbols Subsystem allows the user to specify the location of any file with
construct known as a "pathname." Pathnames have several elements.
The first characters of a pathname may be a slash, followed by a disk packname or
octal logical disk number, followed by another slash
(e.g., "/user disk/" or
"737"), in which case the named disk will be searched for the remainder of the
pathname. The disk name may be omitted, implying that all disks are to be sear-

- 9 -

a

Software Tools Subsystem Tutorial
ched. When a pathname begins with a slash, the file search operation begins in the
master file directory of the disk or disks selected; when it does not begin with a
slash, the file search operation begins in the current directory.
The remainder of the pathname consists of "nodes", separated by slashes.
Each node
contains the name of a sub-directory or a file, possibly followed by a colon (":")
and a password.
For example
bin
extra
mfd :xxxxxx
are nodes.
When nodes are strung together, they describe a path to a file, from anywhere in the
file system.
Hence the term "pathname." For example,
/sys/bin
describes the primary directory named "bin", located on the disk whose packname is "sys".
//extra/users
describes the file named "users" in the directory named "extra" on
disks will be searched);

some

unknown

disk

(all

myfile
describes the file or directory named "myfile" in the current directory;
mydir:pword/file2
describes the file named "file2" in the directory named "mydir" (wi th password npword"),
which must be a sub-directory of the current directory, since the lack of a leading slash
means that the search for the directory is to begin in the current directory.
Certain important Subsystem directories have been given alternative names, called "templates," in order to allow the Subsystem manager to change their location on disk without
disturbing existing programs (or users). A template consists of a 'name surrounded by equals
signs ("="). For example, the Subsystem command directory is named "bin".
On a standard
system, you could list its contents with the command
I f //bin

If the Subsystem Manager at your installation had changed the location of the command directory, the command above would not work.
To avoid this problem, you could use the template
for "binn:
If =bin=
Now your command works regardless of the location of the command directory. There exist templates for all of the most important Subsystem directories; for more information on them, and
on pathnames in general, see the User's Guide to the Primos File System.
Now go back and look at the pathnames in the examples for If.
less mysterious.

They should be somewhat

The 'Cat' Command
'Cat' is an alias for Kernighan and Plauger's program 'concat', which appears on page 78
of Software Tools.
It has a simple function:
to concatenate the files named in its argument
list, and print them on standard output. If no files are named, it takes input from standard
input.
(More on standard input and output in the next section, which has examples using
'cat.'
For now, just assume that standard input comes from the terminal and standard output
goes to the terminal.)
Here are some samples of how to use 'cat'.
following section.
cat myfile
cat partl part2 part3
cat

For more important and useful ones, see

(1)
(2)
(3)

- 10 -

the

Software Tbols Subsystem TUtorial
(1)

Prints the file named "myfile" on the user's terminal;
concatenated with nothing and printed on standard output.

i.e.,

"myfile"

(2)

Prints the concatenation of the files named "partl", "part2", and
terminal.

(3)

Copies standard input to standard output. On a terminal, this would cause anything
you typed to 'cat' to be echoed back to you.
(If you try this, the way to stop is
to type a control-c as the first character on the line. As we said before, lots of
programs use this end-of-file convention.)

"part3"

on

is
the

Deleting Files
Sooner or later, you will find it necessary to get rid of some files.
serves this need very nicely.
It is used like this:
del

filel

file2

The 'del' command

file3

to remove as many files as you wish. Remember that each file can be specified by a pathname,
so you are not limited to deleting files in your current directory.
The Subsystem Postal Service
In order to facilitate communic.ation among users, the Subsystem supports a postal
vice in the form of the 'mail' command.. 'Mail' can be used in either of two ways:

ser-

mail
which looks to see if you have been sent any mail, prints it on your terminal, and asks if
you would like your mail to be saved, or
mail login_name
which accepts input from standard" input and sends it to the mailbox of the user whose login
name is "login name". Used in this fashion, 'mail' reads until it sees an end-of-file.
From
the terminal,- this means until you type a control-c in column 1. Your letter is postmarked
with the day, date and time of mailing and with your login name.
Whenever you enter the Subsystem (by typing "swt") a check is made to see if you have
received any mail.
If you have, you are told so.
When you receive your mail (by typing
"mail"), you are asked if you want it to be saved.
If you reply "n", the mail you have just
received will be discarded.
Otherwise, it is appended to the file "=mailfile=", which is
located in your profile directory.
(You can look at it with 'cat', print it with 'pr', or do
anything else you wish to it, simply by giving its name to the proper command. For example,
cat =mailfile=
would print all your saved mail on your terminal.)
The Subsystem News Service
Whereas 'mail' is designed for person to person communication, the Subsystem news service is intended for the publication of articles that appeal to a more general interest. The
news service is implemented by three commands:
'subscribe', 'publish' and 'news'. The use
of the first two should be obvious.
If you wish to subscribe to the new service, simply type
subscribe
and then, whenever anyone publishes an article, a copy of it will be delivered to your news
box.
(You need subscribe to the news service only once; all subscriptions are perpetual.)
Whenever you enter the Subsystem, as with mail, a check is made to see if there is anything
in your news box; if there is, you are given a message to that effect.
Having gotten such a message, you may then read the news at your convenience by typing
news
The news will be printed out on your terminal and then you will be asked whether or not you
want to save it.
If you say "yes", it will be left in your box and you may read it again at
a later date; otherwise, it is discarded. There are other ways to use the 'news' command
- 11 -

Software Tools Subsystem Tutorial
that are fully explained by 'help'.
Now suppose you have a hot story that you want to publish. All you have to do is create
a file (let's call it "article") whose first line is the headline, followed by the text of
the story. Then you type
publish article
and your story will be delivered to all subscribers of the news service.
If you are a subscriber yourself, you can check this with the 'news' command.
In addition, a copy is made in
the news archives.

- 12 -

Software Tools Subsystem Tutorial
Input/Output
One of the most powerful features of the Software Tools Subsystem is its handling of input and output. As much as possible, the Subsystem has been designed to
shield the user from having to be aware of any specific input or output medium; to
present to him, instead, a standardized interface with his environment.
This
facilitates use of programs that work together, without the need for any esoteric
or
complicated programming techniques.
The ability to combine programs as
cooperating tools makes them more versatile; and the Software Tools Subsystem makes
combining them easy.

Standard Input and Standard Output
Several files are always open and available to any program that runs under the Subsystem.
Such files are generically referred to as 'standard ports'; those available for
~nput
are called 'standard inputs', and those available for output are called 'standard outputs' •
Standard inputs and standard outputs are initially assigned to your terminal, and revert
back to those assignments after each program terminates.
However, this can be changed by the
command interpreter without any knowledge on the part of user programs.
This facility is
called "input/output redirection" (or "i/o redirection" for short).
I/O Redirection
As we mentioned, standard input and output are by default assigned to the terminal.
Since this is not always desirable, the command interpreter allows them to be redirected
(reassigned)
to other media. Typically, they are redirected to or from disk files, allowing
one program's output to be saved for later use perhaps as the input to another program. This
opens the possibility for programs to co-operate with each other.
What is more, when
programs can communicate through a common medium such as a disk file, they can be combined in
ways innumerable, and can take on functions easily and naturally that they were never
individually designed for.
A few examples with 'cat' below, will help to make this clear.
However, let us first examine the techniques for directing standard inputs and standard
outputs to things other than the terminal.
The command interpreter supports a special syntax
(called a funnel) for this purpose:
pathname>

(read "from" pathname)

redirects standard input to come from the file named by "pathname";
>pathname

(read "toward" pathname)

redirects standard output to go to the file named by "pathname". For example, suppose you
wanted a copy of your mail, perhaps to look at slowly with the editor.
Instead of typing
mail
which would print your mail on the terminal, you would type
mail >mymail
which causes your mail to be written to the file named "myrnail" in the current directory.
It
is important to realize that 'mail' does nothing special to arrange for this; it still thinks
it is printing mail on the terminal.
It is more important to realize that any program you
write need not be aware of what file or device it is writing on or reading from.
A bit of terminology from Software Tools: programs which read only from standard input,
process the data so gathered, and w"rite only on standard output, are known as "filters."
They are useful in many ways.
Examples of Redirected I/O Using 'Cat'
Now, 'cat' does not seem like a particularly powerful command; all
it can do is
concatenate files and do some peculiar things when it isn't given any arguments. But this
behavior is designed with redirected i/o in mind.
Look through the following examples and
see if they make sense.
cat

file 1

>file2

- 13 -

Software Tools Subsystem Tutorial
What this does is to copy "filel" into nfile2". Note that since 'cat' sends its output to
standard output, we have gained a copy program for free.
cat

filel

file2

file3

>total

This example concatenates "filel", "file2", and "file3 n and places the result in the file
named "total".
This is probably the most common use of 'cat' besides the simple "cat
filename".
cat

>test

This is an easy way to create small files of data.
'Cat' does not see any filenames for it
to take input from, so it reads from standard input. Now, notice that where before, this
simply caused lines to be echoed on the terminal as they were typed, each line is now placed
in the file named "test". As always, end-of-file from the terminal is generated by typing a
control-c in column 1.
One thing that is extremely important is the placement of blanks around i/o redirectors.
A funnel (">") must not be separated from its associated file name, and the entire redirector
must be surroun'O'eir"by at least on blank at each end.
For example, "file> cat" and "cat
>file" are correct, but "file> cat",
"cat> file", "file>cat" and "cat>file" are all
incorrect, and may cause catastrophic results if used!
You can see that more complicated programs can profit greatly from this system of i/o.
After all, from a simple file concatenator we have gained functions that would have to be
performed by separate programs on other systems.

- 14 -

Software Tools Subsystem Tutorial
Using Primos from the Subsystem
Unfortunately, all the functions of Primos and its support programs have not
been neatly bundled into the Subsystem. Three of the Subsystem's commands that
attempt to address this problem are the topic 6f this section.

Executing Primos Commands from the Subsystem
In order to give Subsystem users access to Primos programs and commands without having
to go through the work of leaving and re-entering the Subsystem, the 'x' command provides an
"escape to Primos."
'X, may be used in either of two ways:
x

Primos-command

is the method of choice for executing a single Primos command, while
x

command-l
command-2
command-n
control-c
allows many Primos commands to be executed. Notice that, in this second mode, 'x' is reading
the list of commands from standard input and storing it away. The list is terminated by endof-file, at which point execution of the commands begins. Note also that because of this, a
command such as
command list> x
is perfectly legal.
Using Portran from the Subsystem
The 'fc' command is the Subsystem's interface to Primos' Fortran compiler. As with 'x',
it builds a file containing the Primos commands necessary to run the Fortran compiler, and
then causes Primos to execute the commands in the file. Fortran has many options -- too many
to describe here, or even to remember.
'Fc' automatically selects those options that are
best for programs to run under the Subsystem. Others can be selected, of course, and complete information on what the available options are and how they are invoked can be found
with the 'help' command.
The easiest and most frequent use of 'fc' goes something like this:
fc prog.f
This will cause the Fortran program in the file named nprog.f" to be compiled, with the
binary output going to a file named "pro'1.b".
By default, 'fe' names the output file according to the following convention.
If the
name of the input file ends with n.f", 'fc' replaces the ".f" with ".b" and uses the resulting name as the binary output file. If the name of the input file does not end with n .f",
'fc' just appends the ".b" to it and uses that name for the output file. The following table
illustrates this process:
Fortran input file
cat.f
ftn file
fortran.s

Binary output file
cat.b
ftn file.b
fortran.s.b

If this naming convention is unacceptable for your particular needs, there is a way to circumvent it; as usual, details are available from 'help'.
The Fortran compiler prints a one line summary for each program unit in the input
The summary looks something like this:

file.

nnnn ERRORS [FTN-REV17.3j
where

"nnnn"

is a four digit count of errors encountered, and "routine name" is the name of
-

15 -

Software Tools Subsystem Tutorial
the program unit just compiled.
In addition to this, a diagnostic (though cryptic)
message
conSisting of line number and context is printed for each error encountered.
For help in
decoding these messages and, more importantly, correcting the errors, we suggest that you
consult either a guru or the Fortran manual (Prime publication number PDR3057), whichever is
most handy.
Fortran produces an intermediate binary code that is not directly executable.
In order
to turn it into something useful, Fortran's output must be processed with the Linking Loader,
which we will take up next.
Using the Linking Loader from the Subsystem
As we mentioned above, Fortran's
Loader before it can be executed.
This
to make available to your program the
are likely to have used, and to convert

binary output must be processed by the Primos Linking
step in the program development process is necessary
library and system subroutines and functions that you
it into a form that can be executed.

Unaided use of the Loader can be a painful and finger-fraying experience; much typing
and a good bit of otherwise useless knowledge is required.
For this reason, the 'ld' command
enjoys a prosperous existence.
'Ld'
is to the Linking Loader what 'fc' is to Fortran, even down to the modus operandi;
it builds a file containing the commands that are most frequently used to invoke and control
the Loader, and then hands the file to Primos for execution. The format of the 'ld' command
is (the items enclosed in square brackets are optional):
Id [-u] binary_input_file •.•

[-0 executable file]

If the "_u" option is specified, 'ld' instructs the Loader to tell you the names of any
subroutines or functions
that your program called that were not included in any of the
binary input files.
The "-0" option allows you to specify the name of the file in which to
save the executable version of your program.
If you don't use this option, 'ld' will
construct a default name in a way similar to that used by 'fc':
if the name of the first
binary input file
ends with ".b", 'ld' will replace the ".b" with ".0" and use the resulting
name; otherwise, ".0" is appended to the first binary input file name and that name is used.
It is very important to remember here that the output file associated with an 'ld' command
must be located in the current directory.
This restriction is imposed by the Loader and is
thus beyond the Subsystem's control.
After you type an 'ld' command, you will see a stream of apparent garbage unfold before
your eyes.
This is the contents of the file that 'ld' built being echoed by Primos as it
executes.
Most of this stream is irrelevant. However, there is one important thing to look
for:
if you see a line that contains only
LOAD COMPLETE
this indicates that the operation was successful and that, barring any program logic errors,
your program will execute correctly.
Otherwise, your program has probably called one or more
functions or subroutines that were not contained in any of the binary input files.
(If you
used the "_U" option of 'ld', the Loader has printed a list of names that it did not find. )
The next section contains an example of the use of 'ld.'
'Ld' has other features that we have not mentioned, mainly because effective use of them
requires some familiarity with the Loader.
If you're curious, we refer you to 'help' for the
additional capabilities of
'ld,'
and to Prime's LOAD and SEG Reference Guide (IDR3524) or
Fortran Programmer's Guide (FDR3057) for details on t~Loade~
Warning
Occasionally, the Fortran compiler, the Loader, or a program called by 'x' will bomb out
and leave you stranded outside the Subsystem.
To cure this condition, type
swt
just like you did to enter the Subsystem orignally.

- 16 -

Software Tools Subsystem Tutorial
Program Development
One of the most important uses of the Software Tools Subsystem is program
development. The Ratfor language presented in Software Tools is an elegant
language for software developers, and is the foundation of the Subsystem: virtually
all of the Subsystem is written in Ratfor.

Caveats for Subsystem Programmers
Since the Subsystem is exactly that, not an operating system but a sub-system, programs
written for it must follow a few simple conventions, summarized below.

*

To exit, a program running under the Subsystem should either use a "stop" statement
(Ratfor programs only), or call the subroutine "swt".
Specifically, the Primos
routine "exit" should not be called to terminate a program.
Whenever possible, Subsystem i/o and utility routines should be used instead of
Primos routines, since the latter often do not handle errors in a way suitable for
supporting the Subsystem.
If, however, other i/o routines must be used, remember
that they will not be able to take advantage of standard input and standard output
or of any of the other i/o related features provided by the Subsystem.

The Subsystem Text Editor
The first program most users will see when they wish to create another program is 'ed',
the Subsystem text editor. A complete description of 'ed'
is beyond the scope of this
tutorial, but a short list of commands ~nd their formats, as well as an example, should help
you get started.
For more complete information, refer to Introductio~ to the Software Tools
Text Editor and of course to Software Tools.
'Ed' is an interactive program used for the
may be any collection of characters, such as
program. All editing takes .place in a "buffer",
storage area where it can manipulate your text.

creation and modification of "text". "Text"
a report, a program, or data to be used by a
which is nothing more than 'ed's own private
'Ed's commands have the general format

,
where, typically, both line numbers are optional.
optional parameters.

Commands are one

The symbol  above can have several formats.
an integer, meaning the line with that number.
then the 7th line in the buffer;

letter,

sometimes

with

Among them are:

For example, if the integer is 7,

a period (". ")., meaning the current line;
a dollar sign ("$"), meaning the last line of the buffer:
/string/, meaning the next line containing "string";
string , meaning the previous line containing "string";
any of the above expression elements followed by "+" or "
element.

n

and another

All commands assume certain default values for their line numbers.
the defaults are in parentheses.

expression

In the list below,

Command

Action

(•)a

Appends text from standard input to the buffer after the line
specified.
The append operation is terminated by a line containing
only a period in column 1.
Until that time, though, everything you
type goes into the buffer.

- 17 -

Software Tools Subsystem Tutorial
(• , •)d

Deletes lines
specified.

from

the

first

line

e filename

Fills the buffer from the named file.

(• , • )p

Prints lines from the first line specified to the last.
the entire buffer.

q

Causes 'ed' to return to the command interpreter. Note that unless
you have given a "w" command (see below), everything you have done
to the buffer is lost.

(.)r filename

Reads the contents of the named
specified line.

(. , .) s/old/new/p

Substitutes the string "new" for the string "old".
If the trailing
p is included, the result is printed, otherwise 'ed' stays quiet.

(l,$)w filename

Writes the buffer to the named file.
This command must be
you want to save what you have done to the buffer.

?

Prints a longer description of the last error that occurred.

file

specified

into

the

to

the last line

1, $p prints

buffer

after

the

used

if

If
'ed' is called with a filename as an argument, it automatically performs an "e" command for the user.

'Ed' is extremely quiet. The only diagnostic message issued (except in a time of dire
distress)
is a question mark. Almost always it is obvious to the user what is wrong when
'ed' complains.
However, a longer description of the problem can be had by typing
"?"
as
the next command after the error occurs.
The only commands for which 'ed' provides
unsolicited information are the "e", "r", and "w" commands.
For each of these, the number of
lines transferred between the file and 'ed's buffer is printed.
It should be noted that specifying a line number without a command is
specifying the line number followed by a "p" command; i.e., print that line.

identical

to

Creating a Program
Now that we have a basic knowledge of the editor, we should be able to use it to write a
short program.
As usual, user input is boldfaced.
ed

(1 )

a

t

(2 )

now --- print the current time

(3 )

(4)

*
*

character now (10)

(5 )

call date (TIME OF DAY, now)
call print (STDOUT~ "Now: *s*n.", now

(6)
(7 )

stop
end

(8 )
(9 )

(10)
(11 )

w now.r
11
q

(12)
(13 )
(14)

)

*

(1)

You invoke the editor by typing "ed" after the command interpreter's prompt.
in i tsusual soft-spoken manner, says nothing.

(2)

'Ed's "a" command allows text to be added to the buffer.

(3)

Now you type in the text of the program.
Ratfor.

(4)

Ratfor's built-in macro processor
is used to define a macro with the name
"TIME OF DAY". Whenever this name appears in the program, it will be replaced by
the text appearing after the comma in its definition.
This technique is used to
improve readability and allow quick conversions in the future.

- 18 -

'Ed,'

The sharp sign "#" introduces comments in

Software Tools Subsystem Tutorial

*

(5)

An array "now", of type character, length 10, is declared.

(6)

The library routine "date" is called to determine the current time.

(7)

The library routine "print" is called to perform formatted output to the
standard output port.

(8)

The "stop"
executed.

(9)

The "end" statement marks the end of the program.

statement

causes

a

program's

return to the Subsystem command interpreter when

(10) The period alone on a line terminates the "an command.
done before 'ed' will recognize any further commands.

Remember that this must

be

(11) With the "w" command, 'ed' copies its buffer into the file named "now.rH.
(12)

'Ed'

responds by typing the number of lines written out.

(13)

The "q" command tells ed to quit and return to the Subsystem's command interpreter.

(14) The Subsystem command interpreter prompts with a right bracket, awaiting a new command.
Now we are talking to the command interpreter again. We may now use the 'rp' command to
change our program from Ratfor into Fortran, and hopefully compile and execute it.
rp now.r
(1)
8 (.main.): '(NEWLINE>' missing right parenthesis.

(2)

(3 )

(1)

'Rp'
is called.
The argument "now.r" directs Ratfor to take its input from the
file "now.r" and produce output on the file "now.f".

(2)

'Rp' has detected an error in the Ratfor program.
form
line (program-element):
In this case, a missing

(3)

'Rp's er.ror messages are of

the

'context' explanation

parent~esis

was detected on line 8 in the main program.

'Rp' has returned to the Subsystem's command interpreter, which prompts with "]".

Looking back over the program, we quickly spot the difficulty and proceed to fix it with
'ed' :
] ed now.r
11
8
call print (STDOUT, "Now: *s*n.", now
sf, now/, now)/p
call print (STDOUT, "Now: *s*n.", now)
w
11
q
] rp now.r
]

(1 )

(2)
(3 )
(4 )
(5 )
(6 )
(7 )
(8 )
(9 )

(10)
(11)

(1)

The editor is called as before.
However, since we have given the name of a file,
"now.r", to 'ed' as an argument, it automatically does an "e" command on that file,
bringing it into the buffer.

(2)

'Ed' types the number of lines in the file.

(3)

We type the line number 8,

(4)

'Ed' responds by typing the line.
(Remember that a line number by
same as a "p" command of that line number.)

(5)

We use
'ed's "s" command to add the missing parenthesis.
at the end of the command.

sin~e

that is the line that 'rp' told us had the error.

- 19 -

itself

is

the

Note the use of the "p"

Software Tools Subsystem Tutorial
(6)

'Ed' makes the substitution, and since we have specified the
printed.

(7)

We now write the changed buffer back out to our file ('ed'
"now. rIO for us).

(8)

'Ed' prints the number of lines written.

(9)

We exit from the editor with the quit command "q".

(10) We invoke Ratfor to process the program.
the preprocessing is on file "now.f".

"p",

the

result

is

remembers the file name

Ratfor detects no errors.

The output

of

(11) The command interpreter prompts us for another command.
Now that the Ratfor program has been successfully preprocessed, it is time to compile
the Fortran out!,ut, which was placed in the file "now.f".
'Fc,'
which we covered in the
previous section, should be used to compile Subsystem programs, since it selects several
useful compiler options and standardizes the compilation process:

1 fc now.f
OK, ftn 1/101707 60401
0000 ERRORS [<.MAIN.)FTN-REV17.3]
OK, C 1 2 3
OK, swtrtn -2
]

All of the garbage between the "fc" and the "]" prompt is stuff produced either by
Primos or by the Fortran compiler and is mostly irrelevant at this point. The essential
thing to recognize about it is that the number before "ERRORS" is zero.
Now that our program has compiled successfully, we bravely proceed to invoke the Linking
Loader using 'ld,' which we also covered in the previous section.
Remember that
'fc' has
left the output of Fortran on the file "now.b". We will use 'ld's "-0" option to select the
name of the executable file:

1 Id now.b -0 now
OK, swtseg
[SEG rev 17.3]
it vI II
$ co ab 4001
$ slsy swt$cm 4036 100000
$ slsy swt$tp 2030 150000
$ mi
$ silo now.b 0 4000 4000
$ slli vswtlb 0 4000 4000
$ slli 0 4000 4000
LOAD COMPLETE
$ sa
$ re
it sh
TWO CHARACTER FILE 10: II
CREATING 114000
it delete II
11=

QU

OK, cn 114000 now
OK, swtrtn -2
]

Again, all the noise between "ld" and "]" comes from Primos and the Loader.
The
important thing to notice here is the "LOAD COMPLETE" message, which indicates that linking
is complete. If we did not get the "LOAD COMPLETE" message, we would re-link using the command "ld -u now.b -0 now" and the loader would then list the undefined subprograms.
We now have an executable program in our directory.

We can check this using 'If':

If

now

now.b

now.f

now.r

1
Deciding we do not need the Fortran source file and the intermediate binary file hanging
around, we remove them with 'del':
-

20 -

Software Tools Subsystem Tutorial
] del now.f now.b

] If
now

now.r

]
And getting really brave, we try to run our newly created program:
] now
Now: 16:34:41
]
Hopefully the preceding example will be of some help in the development of your own
(more important) programs. Even though it is simple, it shows almost all the common steps
involved in creating and running a typical p~ogram.

- 21 -

Software Tools Subsystem Tutorial
Advanced Techniques
This
system.

section

deals

with

several

of the more advanced features of the Sub-

Command Files
As an illustration, let us take an operation that finds use quite frequently:
making
printed listings of all the Ratfor source code in a directory. Command language programs, or
"shell programs," greatly simplify the automation of this process. Shell programs are files
containing commands to be executed when human intervention is not required.
Suppose that we put the following commands in a file named nmklist"
redirection here):
-c >templ
tempI> find
.r >temp2
temp2> change % "sp "
temp3> sh
del tempI temp2 temp3

(note the· use of i/o

If

>temp3

Then, whenever we want a listing of all the Ratfor source code in the current
just type:

directory,

we

mklist
The only price we must pay for this convenience is to ensure that the names of all files
containing Ratfor programs end in ".r".
(If the "find", "change", and "sp" commands mystify
you, 'help' can offer explanations.)
Pipes
Pipes are another handy feature of the Subsystem. A "pipe" between two programs simply
connects the standard output of the first to the standard input of the second; and two or
more programs connected in this manner form a "pipeline". With pipes, programs are easily
combined as cooperating tools to perform any number of complex tasks that would otherwise
require special-purpose programs.
The command
binations:

interpreter

provides

a

simple

and

intuitive way to specify these com-

progl I prog2
Essentially, two or more complete commands are typed on the same line, separated by vertical
bars
("I").
(One or more spaces must appear on both sides of this symbol.) The command
interpreter then does all the work in connecting them together so that whatever the program
on the left of the bar writes on its standard output, the one on the right reads from its
standard input.
Take our shell program to create listings as an example; that series of commands
involved the creation of three temporary files.
Not only is this distracting, in that it
takes our ·attention away from the real work at hand, but it also leads to wasted storage
space, since one all too frequently forgets to delete temporary files after they have served
their function.
Using pipes, we could just as easily have done the same thing like this:
1f

-c

find

•r

change

%

"sp n

sh

and the command interpreter would have taken care of all the details that before we had to
attend to ourselves.
In addition to being much cleaner looking, the pipeline's function is
also more obvious.
Additional I/O Redirectors
The last advanced features of the Subsystem we will examine are the two remaining
redirection operators, represented by two variations of the double funnel ("»").
In the first variation,
»xyz

(read "append to xyz")

causes standard output to be appended to the file named "xyz".
-

22 -

Whereas

i/o

Software Tools Subsystem Tutorial
cat filel >file2
would copy the contents of file 1 into file2, destroying whatever was previously in file2,
cat filel »file2
would copy the contents of file 1 to the end of file2, without destroying anything that was
there to start with.
In the second variation, the double funnel is used without a file name

»

(read "from command input")

to connect standard input to the current shell program. For example, suppose we wanted to
make a shell program that extracted the first ten lines of a file, and deleted all the rest.
The shell program might look something like this:
»
ed file
ll,$d

w
q

"»n is frequently used in this way for the editor to read commands from the
without having to have a separate script file.

shell

program,

This is only a very small-sample of the power made available by the features of the Subsystem.
As is the case with any craft, given the proper tools and an hospitable environment
in which to work, the only limlt to the variety of things that can be done is the imagination
and ingenuity of the craftsman himself.

-

23 -

Software Tools Subsystem Tutorial
Background
Ancient History
The Software Tools Subsystem, as it now exists, is in its seventh major revIsIon.
give you an idea of its development, here is a short history of successive versions.

To

Version 1:
Features:
Basic utility commands, no redirection of input or output, low-level
routines for performing file operations but no consistent input/output.
Language:

Fortran

Version 2:
Features: Almost complete set of utility commands, redirection of input and output, all Software Tools i/o routines, Software Tools editor and Ratfor, improved
reliability durIng information passing from one program to another.
Language:
for

Low level routines in Fortran, high level routines and programs in

Rat-

Version 3:
Features:
Same as version 2, but with Primos compatible i/o for speed; New shell
added later greatly expanded program interaction
Language:

Almost entirely Ratfor

Version 4:
Features: Same as version 3, plus:
(1) ability to handle file names of up to 32
characters on new Primos file partitions; (2) much faster disk i/o (On an unloaded
system, benchmarks show an improvement on the order of a factor of 20); (3)
internal reorganization to speed up command searches; (4) Support for virtual mode
programs and a shared command interpreter.
Language: All higher-level routines in Ratfor. A few special routines in assembly
language to provide capabilities not inherent in Fortran.
Version 5:
Features: A new command interpreter supporting arbitrary networks of pipes,
generalized command file handling, and dynamic command line structures was added.
General reorganization of Subsystem directories on disk.
Language:

Ratforand Assembler

(PMA).

Version 6:
Features: Shared libraries, maximal security under
robustness.
Language:

unmodified

Primos,

increased

Ratfor and Assembler (PMA)

Version 7:
Features:
Much faster disk I/O, extensions to pathnames to allow specification of
non-file-system devices, new Ratfor preprocessor with significant extensions, some
general cleanup of code and redundant tools, many additional tools.
Language:

Ratfor, Assembler

(PMA), and some PL/I.

- 24 -

Software Tools Subsystem Tutorial
Authors and Origins
The principal authors of the Software TOols Subsystem are Allen Akin, Perry Flinn, Dan
Forsyth, and Jack Waugh, of the Georgia Institute of Technology, aided by a cast of
thousands.
The ultimate antecedent for the design of the Subsystem is the UNIX operating system,
written by Dennis Ritchie and Ken Thompson of Bell Labs for the DEC PDP-II computers.
The tremendous debt owed to Brian W.
Software Tools, cannot be overstated.

Kernighan

- 25 -

and

P.

J.

Plauger,

the

authors

of

User's Guide to the Primos File System

II

Perry B. Flinn

School of Information and Computer Science
Georgia Institute of Technology
Atlanta, Georgia 30332
March, 1980

TABLE OF CONTENTS

Introduction
What is a File? •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Entrynames ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••.•••••••••
Di rector ies •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Logical Disks •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
The "Current" .and "Home" Directories ••••••••••••••••••••••••••••••••••••••••••••••
Protection and Access Control •••••••••••••••••••••••••••••••••••••••••••••••••••••
Pa thnames •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Passwords in Pathnames •••••••••••••••••••••••••••••••••••••••••••••••••.••••••••••
Templa tes ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••.••••••••••
Device Names •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••.•••.••••••
Georg ia Tech Extensions •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

iii

1
1
1
1
2
2
2
3

4
4
6
6

File System User's Guide
Introduction
One thing that you will almost certainly encounter frequently during your exploits in
the Software Tools Subsystem is the Primos file system. Indeed, there is hardly anything you
can do that does not in some way involve this ubiquitous beast. Recognizing this fact, we
offer this guide as an attempt to acquaint you with everything you need to know to make
effective use of the file system from within the Subsystem. Al though we have tried to be
thorough in our coverage of concepts and features, we have specifically avoided the details
of the programmer's interface to the file system, and everything having to do with
implementation.
Should you find yourself in need of further information in either of these
areas, let us direct your attention to section two of The Software Tools Subsystem Reference
Manual and to the Reference Guide, File Management System (Prime publication number FDR31l0).
What is a File?
A file is a named collection of information retained on some storage medium such as a
disk pack.
Just what kind of information a file contains isn't of much concern to us here;
it may be ASCII character codes that form the text of a book or a program's source code, it
may be arbitrary binary machine words to be used as input data for a program, or it may be
the actual machine instructions of the program itself, to mention just a few. No matter what
form the information in a file takes, as far as Primos is concerned it is just an ordered
sequence of sixteen bit binary numbers. The interpretation of those numbers is left to other
programs.
Entrynames
Since we mentioned that a file has a name, you might ask what names are acceptable.
A
file is known by something called its "entryname." An entryname is a sequence of 32 or fewer
characters ·chosen from the letters of the alphabet, the decimal digits, and the following
special characters:

#

$

I

*

&

The first character in the entryname must not be a digit.
Also, no distinction is
between upper- and lower-case letters. Thus "file name" and "FILE NAME" are the same.

made

Even though Primos allows you to use slashes (/) in entrynames, for reasons. that will
become apparent in the section on pathnames they must be treated specially when you are using
the Subsystem. Because the slash is usej to separate entrynames from one another in pathnames, if you want to use it in an entryname you have to "escape" it. By this we mean that
you have to precede it with the--.rescape" character "@". The "@" simply tells the Subsystem
to "treat the next character literally, no matter what special meaning it may have;" it is
~ taken as part of the entryname.
It is important that you realize this caveat applies
only when you are dealing with the Subsystem; if you try to put an "@" in an entryname when
talking directly to Primos, you will get a rather impudent message.
Directories
The way that Primos makes the association between a file's entryname and its contents is
through the use of "directories." Like a file, a directory has an entryname and contains
some information; but it is different from ordinary files in that the information it contains
is treated specially by Primos.
The information in a directory is a series of "entries,"
each consisting of the entryname of some other file, that file's location on the disk pack,
and some other stuff that we will cover in a later section. When a file's entryname and
location appear in a directory, we say that the directory "contains" that file, or that the
file "resides within" that directory.
Either way you say it, every file in the system
appears in exactly one directory.
Since a directory is so much like a file, there is really nothing to prevent us from
having directories that contain other directories. This phenomenon is known as "nesting" and
may be carried out to any depth, giving rise to a hierarchical structure:
mfd

I
I

I

I

dirl

disk rat

I

I

dir3

topmost

level

I

I

I

filel

dir4

I

boot

I

filel

I
dirl

I

I

the

I

dir2

file2
At

I

badspt

mfd

':ilel
of

the

hierar~hy

is a directory named "mfd", short for master file
-

1 -

File System User's Guide
~irectory.

You will find this directory at the top level of every Primos file
system.
The
MFD is special because it always begins at a fixed location on the disk pack, and because it
always contains the following entries:
disk rat
-The disk rat (disk record availability table) is a file that catalogs all of the
storage -space~ the disk pack that isn't already in use.
It is always the first
entry in the MFD and, like the MFD, always begins at a fixed location.
This file
may have any valid entryname;
it doesn't have to be called "disk_rat". But
whatever entryname is chosen, it is known as the "packname" for that disk pack.
mfd
The MFD always has an entry describing itself.
boot
The "boot" file, which also begins at a fixed location, contains the memory-image
of a program that is loaded and executed whenever the computer is cold-started.
This program is usually a single-user version of Primos.
badspt
Although this file is not necessarily present on every disk
contains a list of faulty records that should not be used.

pack,

if

it

is

it

You may have noticed in the diagram that there are three occurrences of the entryname
"filel", and two of "dirl". Each of these entrynames refers to a different file or directory.
Even though each entryname must be unique among all those in a given directory, it is
perfectly legal to use the same name repeatedly in different directories.
Logical Disks
Since Primos doesn't allow file systems that span mUltiple disk packs, it does the next
best thing and allows you to have multiple file systems in the same installation.
Each file
system is called a "logical disk" and has exactly the structure described in the last section.
Although each installation is virtually guaranteed to have at least one logical disk,
the actual number may vary dynamically from 0 to 62.
Each disk is uniquely identified by its
"logical disk number," and though it is not required, it is extremely desirable for each disk
to have a unique packname.
The ·Current" and "Home" Directories
Now that we have described this wonderful hierarchy of directories and files just waiting to be used, you might wonder how it is that you go about getting to them.
One concept
that is central to the solution of this problem is that of the "current directory."
From the
time you log in to the time you log out, your terminal is having an ongoing relationship wi th
some directory in the file system. When you first log in, this directory is typically the
one whose entryname matches your login name and which resides in some MFD.
But monogamy is
not required; you are free to jump around from directory to directory upon the slightest
whim. We say the "current directory" is the directory to which you are attached.
The current directory is important because all the files contained in it are directly
accessible to you at the drop of an entryname.
In fact, if you are using some of Prime's
software, these are the only files accessible to you without changing your current directory.
But there is a handy device called the "home directory" that takes some of the edge off of
this restriction. Your home directory is the one to which you intend to return after an
expedition into the wilds of the file system.
In effect, it allows you to remember the location of some particular directory, and to later return there in one giant step, regardless of
your
(then) current location. Whenever you change your current directory, you get to choose
whether to change your nome directory as well or to ldave it where it is.
Protection and Access Control
So that you can guard your files from unwanted perusal or alteration, the file system
includes a basic access control mechanism that provides two levels of protection to each
file.
As part of this mechanism, each directory has associated with it a pair of sixcharacter passwdrds, one called the "owner password," and the other called the "non-owner
password." Normally, when a directory is created its owner password is blank and its nonowner password is zero; these are the default values.
But if the passwords have other than
default values, then before you can successfully attach to the directory, you must prove your
worthiness to do so by citing one of them.
If you cite the owner password,
then you are
attached to the directory with "owner status;" if it's the non-owner password that you cite,
then you are attached with "non-owner status."
If you fail to cite either password,
then
unless one of them has a default value your attempt will be in vain. Just what status you
attain when attaching to a directory bears upon the kinds of things you may do to the files
-

2 -

File System User's Guide
it contains.
For the purposes of protection, there are three things you can do to a file:
you can
read from it, you can write into it, and you can truncate (shorten) or delete it.
Now if you
will recall that "other stuff" we mentioned a while back as being in a file's directory
ehtry, part of it is two sets of "protection keys:" one for people attached to the containing directory with owner status, and the other for those with non-owner status. Each set of
keys has a bit for each type of access:
read, write and delete.
If a bit is turned on, the
associated type of access is permitted; otherwise, it is denied.
Pathnames
Unlike the Prime software we mentioned that only lets you manipulate
files in your
current directory, the Subsystem places no restrictions on the whereabouts of the files you
can reference. Generally speaking, anyw,ere the name of a file
is required you may use
something called a "pathname." A pathname is a construct that allows you to uniquely specify
any file
in the system by describing a path to it from some known point. As we have seen,
the current directory is one such point, and because of its fixed location, the MFD on each
logical disk is another.
The syntax of a path name is divided into two basic parts which we will call the "starting node," designating the particular known point at which the path starts, and the "directory path," designating the actual s~ries of nested directories that leads to the desired
file.
Both parts, by the way, are optional: either one may stand alone,
they may stand
together, or they may both be omitted. But if both are present, they must be separated by a
single slash (/).
The starting node of a pathname com~s in two varieties. The first designates the MFD of
a particular logical disk and consists of an initial slash followed by a packname, a logical
disk number in octal, or a single asterisk (*):
/volOO
/7
/*
If
the asterisk is used,
the MFD of the logical disk containing the current directory is
implied; the other two forms should be self-explanatory.
The second variety of starting node
refers to one of the current directory's ancestors in the hierarchy and consists of one or
more backslashes (\).
The number of backslashes indicates the number of nesting levels above
the current directory at which the path begins.
If the starting node is omitted altogether,
then the path starts in the current directory.
Now the other half of a pathname, the directory path, is simply a series of one or more
entrynames, each separated from the next by a single slash.
The first entryname must be
contained in the starting directory, and each subsequent entryname must reside in the directory designated by the preceding entryname.
The very last entryname in the path is that of
the target file. To illustrate,
src/lib/swt
extra
are proper directory paths. As you might expect, if the directory path is omitted, the target of the pathname is the starting dire{~tory.
Thus, the pathname from which both the starting node and the directory path have been omitted (the empty pathname) refers to the current
directory.
A couple of special cases are worth mentioning here:
First, a pathname that begins with
a slash and whose directory path is not omitted need not contain a packname or logical disk
number.
In this case an implic~s~arch of the MFD on each logical disk is made for the
first entryname in the directory path.
The MFD on the lowest numbered logical disk in which
that entryname is found is taken as the starting directory.
Notice that such a pathname is
easily recognizable because it begins with two slashes; the first one belongs to the starting
node and the second separates it from the directory path:
//system
The second special case has to do with pathnames beginning with a backslash.
Although
we said that a slash must be used to separate a starting node from a directory path, when
using backslashes the intervening slash is not required; indeed it is omitted more often than
not.

- 3 -

File System User's Guide
Passwords in Pathnames
Thus far in discussing pathnames we have assumed that we may freely specify any valid
sequence of directories in a directory path without regard to the passwords that may be
associated with those directories. In fact, this is true only if the directories have at
least one password with a default value. You see, the interpretation of a pathname involves
temporarily attaching to each directory in the path; if this can't be done without a password
then the pathname can't be interpreted.
Furthermore, the set of access privileges (owner or
non-owner)
available to you with respect to the target file is determined by whether you are
attached to its parent directory as an owner or a non-owner by the pathname interpreter. So,
to let you deal effectively with passworded directories, the pathname syntax allows you to
append a password to each directory entryname in the path, separated from the entryname by a
colon:
entryname:passwd
If a password is so specified, the pathname interpreter will use it
associated directory.

when

attaching

to

the

A password may contain arbitrary characters which are not necessarily legal in
entrynames.
So to avoid the ambiguity in interpretin1 a password containing a slash, as with
entrynames, the slash must be "escaped" by preceding it with an "@". This also means that
the "@" itself must be escaped if it is to appear literally in the password. Remember that
the "@" used as· an escape character is not included in the password; it merely turns off the
special meaning of the character that follows.
The following set of examples contains an instance of just about every possible variation in the syntax of pathnames, along with an explanation of each.
A formal summary of
pathname syntax in BNF notation is included in Appendix B.

a fi Ie
A file in the current directory whose entryname is "a file".
a ufd/a file
A -file whose entryname is also
"a ufd" of the current directory.

"a file"

and is contained in the subdirectory

\
The parent of the current directory.
\brother (or \/brother)
The file or directory named "brother" that
contains the current one.

resides

in

the

same

directory

that

IO/cmdncO:secret
The directory named ncmdncO" (one of whose passwords is "secret") which resides in
the MFD on logical disk O.

Imd
The MFD on the logical disk whose packname is "md".
1*/boot
The "boot" file on the current logical disk.
Iispoolq/q.ctrl
The file named "q.ctrl" in the "spoolq" directory on the
disk that has one.

lowest

numbered

logical

ki@/da:ad@/ik
The directory residing in the current dire:::tory whose entryname is "ki/da" and one
of whose passwords is nad/ik"~
(Note the use of the n@" to turn off the special
meaning of "I".)

The current directory.
Templates
In order to provide flexibility in the organization and placement of the directories and
files used by the Subsystem, the pathname interpreter contains a primitive macro substitution
facility, a feature that is loosely referred to as "templates." Templates provide a means
for designating particular files or directories without having to know their exact location
in the file system, and for constructing file names whose exact interpretation may vary with
the context in which, or the user by whom they are used. A template simply consists of a
name
(made up of letters, digits and underscores, and beginning with a letter) enclosed in

- 4 -

File System User's Guide
equals bars (=).
Unlike entrynames, upper- and lower-case letters are different in template
names;
"name" and "NAME" are not the same.
Each defined templatehas an associated value
which is an arbitrary character string.
The effect of including a template in a pathname is
the same as if its value had appeared in3tead.
There are two types of templates:
static and dynamic.
The value of a dynamic template
varies depending upon who you are, how you are connected to the computer, or what time it is.
The following list describes all of the available dynamic templates:
"date"
The current date in the format mmddyy.
"day=
The current day of the week; ",nonday", for example.
"passwd"
The owner password of the curr~nt user's profile directory.
sword the Subsystem asked you for when you typed "swt".)

(This is the same pas-

=pid=
The current user's process-id. This is a two-digit number in the range 01-63
is unique to each logged-in us~r.

that

=time=
The current time in the format hhmmss.
=user=
The current user's login name.
These templates are particularly useful Eor constructing unique file names.
Static templates are those whos'? definitions are independent of the context in which
they are used.
These templates and theic values come from two sources.
The file whose name
is the value of the template
=template=
contains template definitions that apply globally to all Subsystem users.
In fact the
definition of =template= itself is contained in this file,
as are definitions for other
important Subsystem files and directories.
In addition to this file, you may have in your
profile directory (named by the template =varsdir=) a file named ".template" that contains
your own personal template definitions.
Any templates that you define yourself preempt
similarly-named system and dynamic templ,ltes, so you should exercise caution in choosing
names. Also note that any new templates you place in your personal template file do not take
effect until the next time you enter th.~ Subsystem via 'swt'; this is the only time that the
file is examined.
The format o'f both files is the sam·~:
a series of lines containing a name, followed by
one or more blanks, and then a value.
Blank lines are ignored, as are leading and trailing
blanks on each line.
Comments may be introduced with the sharp character (i); all characters
from the sharp to the end of the line are ignored:

i example of a template defini~ion
template_name
template_value

# comment

A quick perusal of the contents of =template= should clear up any lingering questions you may
have.
Just for convenience, all the standard templates, along with an explanation of each,
are listed in Appendix A.
If you look at the template definition file,
you will notice that some of the
definitions appear to contain templates i:hemselves.
This is perfectly legal, for after each
template
is expanded,
the result is inspected for further templates until no others are
found.
This makes possible the definition of such templates as
"=varsdir=", and generally
enhances the utility of the mechanism.
Just one further remark about templ,ates:
Remember the trouble we had with "/" in passwords and entrynames? Well, we have a Similar situation with "="; when should it be taken
literally,
and when should it indicate the beginning of a template? To solve this dilemma,
any time the template expander sees a ter'lplate with an empty name (that is,
two consecutive
equals bars),
it supplies a single "=" as the replacement value and does not consider it to
be the start of another template.
So if you ever want a literal "=", in a password for example, just type "==" and you've got it.

-

5 -

File System User's Guide
Device Names
Up to this point, we have been talking only about disk files, and the path names we have
described have corresponded exactly to some actual sequence of directories leading to a file.
Although this is certainly the most common use of pathnames, there is one additional feature
that significantly enhances their usefulness.
If the "starting node" of a pathname is
"/dev", the path name doesn't necessarily refer to a disk file, but may instead refer to an
arbitrary peripheral device, or to some special file that requires unusual processing.
As
with ordinary pathnames, the "directory path" provides more information about the target file
or device.
Perhaps the most
usually called) is

useful

of

these extended pathnames (or "device names," as they are

/dev/lps
which refers to the line printer spooler. When this pathname is opened for writing, a
special disk file is created and other processing is done so that when the file is closed,
its contents will be written to the on-site line printer by the spooler and then deleted.
Additional entrynames may be included after the "Ips" to select various processing options
specific to the spooling process. A complete list of these in included as Appendix c.
Another useful device name is
/dev/tty
which refers to your terminal device. There are also others which, when opened,
descriptors for the various standard input and output ports:
/dev/stdout
/dev/stdoutl
/dev/stdout2
/dev/stdout3
/dev/errout

yield

file

/dev/stdin
/dev/stdinl
/dev/stdin2
/dev/stdin3
/dev/errin

Finally, the device name
/dev/null
when opened yields a file descriptor which discards all data written to it and returns an
end-of-file signal every time it is read.
It is really just a fancy name for the proverbial
bit bucket.
Georgia Tech Extensions
As many of you reading this guide will eventually come to know, using the standard
Primos file system can be quite awkward, principally because, of the constant necessity of
typing passwords in pathnames.
Relief from this burden comes only at the expense of
security, which in many cases is a more important consideration than ease of use. So that we
can have our cake and eat it' too, we at Georgia Tech have made a few modifications' to the
standard protection mechanism that virtually eliminate the necessity for typing passwords in
all but the rarest of circumstances. The Subsystem requires none of these modifications to
operate properly, 'and in those cases where it behaves differently depending on the extant
version of Primos, it does so completely transparently to the user.
In Georgia Tech Primos, if a directory's owner password is a valid entryname, it is
assumed to be the login name of the user that "owns" that directory.
In this case, the
"owner password" is instead called the "owner name." When you attach to a directory whose
owner name "matches" your login name, you automatically get owner status without having to
cite a password. The word "match" is quoted in the last sentence because more is meant by it
than just character-for-character equality. The underscore
()
is treated as a "wild"
character:
whenever it appears in a given position in either-your login name or the directory's owner name, the two names are considered equal in that position.
Thus, a directory
whose owner name i s "
" can be attached with owner status by everyone. Likewise, if
your login name is "
n then you get automatic owner status
in any directory with an
owner name instead of an owner password. With judicious assignment of login names, this
feature may be used to effect very convenient sharing of files by multiple users working on
the same project.
Just as icing on the cake, anyone logged in with the name "system" gets
owner status in every directory, regardless of whether it has an owner name or an owner password.
The modifications described in the last paragrapll constitute all of
differences between the protection mechanism in Georgia Tech Primos
mechanism. In all other situations, you can expect tne standard behavior.

- 6 -

the substantive
and the standard

File System User's Guide
Appendix A - Standard Templates
The following list describes all of the templates that are provided either in the
dard Subsystem template file or by the template interpreter.

stan-

=aUx=
This Subsystem directory contains large files that are not absolutely necessary for
the operation of the Subsystem.
=bin=
The standard Subsystem command directory.
=cmdncO=
The directory to which the system console is normally attached.
=date=
The current date in the format mmddyy.
=day=
The current day of the week (e.g., "monday", "tuesday", etc.).
=dictionary=
A file containing English words, used by the spelling checker.
=doc=
The Subsystem documentation directory.
=extra=
A standard Subsystem directory containing miscellaneous files required for proper
operation of the Subsystem.
=fmac=
The Subsystem directory contai,ing all the text formatter macro definition files.
=GaTech=
This is a template having nothing to do with pathnames.
Its value is "yes" at
installations that run the Georg ia Tech version of Primos, and "no" elsewhere.
Programs that are sensitive to the operating system version use this template to
determine their environment.
=gossip=
The directory containing user-to-user message files generated by the 'to' command.
=home=
The current user's login directory. Take note that this is not the same as his
"home directory" as described in the section on "current" and "home" directories.
=incl=
The standard Subsystem directory containing
programs.

files

that

are

included

by

Ratfor

=installation=
A file containing the name of the installation.
=lbin=
The standard Subsystem locally-supported-command directory.
=lib=
The Pr imos directory containi:1g all library files that should be accessible to the
loader.
=mai 1=
The Subsystem directory that contains per-user mail delivery files.
=mailfile=
The current user's mail storage file. This is where the 'mail' command deposits
letter after you have asked thot it be saved.
=newbin=
The Subsystem directory into which
recompilation of the entire Suhsystem.

newly-compiled commands are placed during a

=newlbin=
The Subsystem directory into which newly-compiled locally-supported-commands
placed during a recompilation 0f the entire Subsystem.

- 7 -

a

are

File System User's Guide
=newlib=
The Subsystem directory into which newly-compiled object code libraries are placed
during a recompilation of the entire Subsystem.
=news=
The directory used by the Subsystem news service.
=newsfile=
The current user's news delivery file.
=passwd=
The password of the current user's profile directory.
the Subsystem asked you for when you typed "swt".)

(This is the

same

password

=pid=
The current user's process-id. This is a two-digit number in the range 01-63 that
is unique to each logged-in user.
=src=
The Subsystem source code directory.
=srcloc=
A file associating each Subsystem library subroutine and
name(s) of its source code file(s).

command

with

the

path-

=swtrtn=
The value of this template is the entryname of the 'swtrtn' program in the directory =cmdncO=.
=system=
The Primos directory that contains the core-images of
segments.

the

various

shared

memory

=temp=
The Subsystem directory in which all temporary files are created.
=template=
The system template definition file.
=termlist=
A file describing the location and type of each terminal connected to the computer.
=time=
The current time in the format hhmmss.
=user=
The current user's login name.
=userlist=
A file containing a list of all users authorized to use the computer.
=utemplate=
The current user's private template definition file.
=vars=
The Subsystem directory in which all per-user profile directories are contained.
=varsdir=
The current user's profile directory.
=varsfile=
The current user's shell variable storage file.
=vth=
The directory used by the Subsystem virtual terminal handler.

- 8 -

File System User's Guide
Appendix B - Pathname Syntax
For the grammar afficionados among you, here is a formal description of the syntax of
pathnames. The notation used is an exte,ded Backus-Naur Form (BMF) which is described in the
introduction to the Software Tools Subsystem Reference Manual.














::= 

/

::= \{\}
/
::= 


*

::= 

::= {/}
::= [:l
::= {}
::=  I 
::= 
I 
::= a

::= 0
::= •

I b I c 1••• 1 x I y I z
I 1 I 2 1••• 1 7 I 8 I 9
I $ I & I - I * I
I /

Appendix C - Spool Options
The entrynames that may be appended to the "/dev/lps" device name to control spooling
options are summarized in the following list. These entrynames correspond exactly to the
options that are accepted by the 'sp' cOlnmand (see section one of the Subsystem reference
manual) •
a

This option selects a specific location at which the file is to be printed. The
immediately following entryname in the path is taken as the name of the destination
printer.

b

The file name that is printed on the banner page of the printout may be set
arbitrarily with this option. The next entryname in the path is taken as the name
to be printed.
If this option is not used, the name "/dev/lps" is printed.

c

This option specifies the number of copies of the file that are to be printed.
next entryname must be a decim,~l integer indicating the number of copies.

d

Printing of the file may be deferred until a specific time of day using this
option.
The next entryname in the path must be a time of day in any reasonable
format.

f

If specified, this option indicates that the print file contains
carriage control characters.

h

This option causes the spooler to suppress the printing of the banner page that
normally precedes each printout.

j

Specifying this option causes the spooler to suppress the trailing page eject
it normally supplies at the end of each printout.

n

This option causes the spooler to print a consecutive line number in front of each
line of the print file.

p

This option instructs the spooler that the print file is to be printed on a special
type of paper. The name of th,! desired form should follow as the next entryname in
the path.

r

"Raw" forms control mode is selected by this option. No carriage control characters are recognized, nor is any pagination done when this mode is in effect.

s

This option selects the stan~ard Primos forms control mode. Under this mode, the
printout is automatically paginated, and a header line is printed on each page.

-

9 -

standard

The

Fortran

that

Introduction to the Software Tools Text Editor

II
T. Allen Akin

Perry B. Flinn
Daniel H. Forsyth, Jr.

School of Information and Computer Science
Georgia I~stitute of Technology
Atlanta, Geo~gia 30332
April, 1980

TABLE OF CONTENTS

Tutorial •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Starting an Editing Session. ••••••••.•••••••• ••••• •••••• •••••••••••••••••• ••••• •••
Entering Text - the Append Command ••••••••••••••••••••••••••••••••••••••••••••••••
Writing text on a file - the Write command ••••••••••••••••••••••••••••••••••••••••
Finishing up - the Quit command •••••••••••••••••••••••••••••••••••••••••••••••••••
Reading files - the Enter command •••••••••••••••••••••••••••••••••••••••••••••••••
Errors - the Query command ••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Printing text - the Print command •••••••••••••••••••••••••••••••••••••••••••••••••
More Complicated Line Numbers •••••••••••••••••••••••••••••••••••••••••••••••••••••
Deleting Lines ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Text Patterns •••••••••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Making Substitutions - the Subs~itute command •••••••••••••••••••••••••••••••••••••
Line Changes and Insertions •••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Moving Text •••••••••••••••••••••••••.••••••••••••••••••••••••••••••••••.••••••••••
Global Commands •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Marking Lines •••••••••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Undoing Things -- the Undo Command ••.•••••••••••••••••••••••••••••••••••••••••••••
Summary...........................................................................

1
1
1
1
2
2
3
3
4
5
6
8
9
10
10
11
12
13

The Subsys tern Sc reen Ed i to r ••••••••••••.••••••••••••••••••••••••••••••••••.••••••••••
Invoking the Screen Editor ••• •••••••.•••••••••••••••••• ••••••••••••••••••••• ••••••
Using 'Se' ••• •••••• •••••••••••••• ••••••••••••••••••••• ••• ••••••••••••••••••• ••••••
Extended Line Numbers •• ~..........................................................
Case Conversion •••••••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Tabs ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Full-Screen Editing •••••••••••••••••.••••••••••••••••••••••••••••••••••.••••••••••
Horizontal Cursor Motion ••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Vertical Cursor Motion ••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Character Insertion •••••••••••••••••.•••••••••••••.•••••••••••••••••••••••••••••••
Character Deletion................................................................
Te rm ina t i ng a Li n e ••••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••
Non-printing Characters •••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••

14
14
14
15
15
16
16
16
17
17
17
18
18

Screen Editor Options

19

Screen Editor Control Characters

21

Ed i tor Command Summary •••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••

23

Elements of Line Number Expressions ••••.•••••••••••••••••••••••••••••••••••••••••••••

26

Summary of> Paftern Elements

26

iii

Foreword
'Ed'
is an interactive program that can be l sed for the creation and modification o£
"text." "Text" may be any collection of character dBta, such as a report, a program, or data
to be used by a program.
This document is intended to provide the beginning user of 'ed' with a tutorial, an aid
to becoming familiar with editing.
It does not attempt to cover the editor in full; only the
most frequently used aspects are mentioned.
For details on advanced uses, a careful reading
of Software Tools and the Software Tools Subsystem Reference Manual is recommended.

How To Use This Guide
This tutorial includes a step-by-step journey through an editing session.
You should be
sitting at a terminal and running the Software Tools Subsystem, so that you can perform the
suggesteo exercises as you go.
Throughout the text of this guide are sample editing commands, which you can execute on
your terminal to get a feel for their actual effect.
If at any time your terminal session
produces results different from those shown in the text, carefully re-check what you have
typed, or consult someone in charge of your installation.

- iv -

Introduction to 'Ed'
Tutorial
Starting an Editing Session
We assume that you have successfully logged in to your computer and are running the
Software Tools Subsystem.
If you need assistance, see the Software Tools Subsystem Tutorial.
We further assume that you know how to use the character erase and line delete characters, so
that you will have no trouble correcting typographical errors, and that you have some idea of
wh a t a "f i 1 e " is.
Since you are
in the Subsystem, the command interpreter should have just printed the
prompt "]". To enter the text editor, type
ed

(followed by a newline)

(Throughout this guide, boldface is used to indicate information that you should type in.
Things typed by 'ed' are shown in the reqular font.)
You are now in the editor, ready to go.
Note that 'ed' does not print any prompting information; this quiet behavior is preferred by
experienced users.
(If you would like
a
prompt,
it can be provided; try the command
"op/prompt/".)
,
At this point,
'ed'
is waiting for instructions from you.
You can instruct 'ed' by
using "commands", which are single letters (occasionally accompanied by other information,
which you will see shortly}.
Entering Text - the Append Command
The first thing that you need is te~t to edit. Working with 'ed' is like working with a
blank sheet of paper;
you write on the paper, alter or add to what you have written, and
either file the paper away for further use or throw it away.
In 'ed's terminology, the blank
sheet of paper you start with is called 1 "buffer."
The buffer is empty when you start
editing. All editing operations take pllce in the buffer; nothing you do can affect any file
'unless you make an explicit request to transfer the contents of the buffer to a file.
So the first problem reduces to finding a way to put text into the buffer.
command is used to do this:

The "append"

a
This command appends (adds)

text lines to the buffer, as they are typed in.

To put text into the buffer, simply type it in, terminating each line with a newline:
The quick brown fox
jumps over
the lazy dog.
To stop entering text, you must enter a line containing only a period, immediately followed
by a newline, as in the last line above.
This tells 'ed' that you are finished writing on
the buffer, and are ready to do some editing.
The buffer now contains:
The quick brown fox
jumps over
the lazy dog.
Neither the append command nor the fin,l period are included in the buffer -- just the text
you typed in between them.
Writing text on a file - the Write command
Now that you have some text in the ~uffer, you need to know how to save it.
command "w" is used for this purpose.
I~ is used like this:

The

write

w file
where "file" is the name of the file use:l to store what you just typed in. The write command
copies the contents of the buffer to che named file, destroying whatever was previously in
the file.
The buffer, however, remains intact; whatever you typed in is still there.
To
indicate that the transfer of data was successful, 'ed' types out the number of lines written.
In this example, 'ed' would type:
-

I

-

Introduction to 'Ed'
3

It is advisable to write the contents of the buffer out to a file periodically, to insure
that you have an up-to-date version in case of some terrible catastrophe (like a system
crash) •
Finishing up - the Quit command
Now that you have saved your text in a file,
"quit" command "q" is provided for this:

YOLo

may wish

to

leave

the

editor.

The

q

The next thing you see should be the "]" prompt from the Subsystem command interpreter.
you did not write out the contents of the buffer, the edi tor would respond:

If

?

(not saved)
This is to remind you to write out the buffer, so that the results of your editing session
are not lost.
If you intended that the buffer be discarded, just enter "q" again and 'ed'
will throwaway the buffer and terminate.
When you receive the "]" prompt from the Subsystem command interpreter, the buffer has
been thrown away~ there is absolutely no way to recover it.
If you wrote the contents of the
buffer to a file, then this is of no concern~ if you did not, it may mean disaster.
To check if the text you typed in is really in the file you wrote it to, try the following command:
] cat file
where "file" is the name of the file given with the "w" command.
("Cat" is a Subsystem' command that can be used to print files on the terminal.
If, for example, you wished to print
your file on the line printer, you could say:
] pr file
and the contents of "file" would be queued for printing.)
Reading files - the Enter command
Of course, most of the time you will not be entering text into the buffer for the first
time.
You need a way to fill the buffer with the contents of some file that already exists,
so that you can modify it. This is the purpose of the "enter" command "e"~ it enters the
contents of a file into the buffer.
To tryout "enter," you must first get back into the
ed itor:

1 ed
"Enter" is used like this:
e file
"File" is the name of a file to be read into the buffer.
Note that you are not restricted to editing files in the current directory~ you may also
edit files belonging to other users (provided they have given you permission).
Files belonging to other users must be identified by their full "pathname" (discussed fully in User's
Guide to the Primos File System).
For example, to e(nt a file named "document" belonging to
User"l:Om--;-OO-you woulaenter the following command:
e Iitomidocument

read.

After the file's contents are copied into the buffer, 'ed' prints the number of lines it
In our example, the buffer would now contain:
The quick brown fox
jumps over
the lazy dog.

If anything
named file.

at all is present in the buffer, the "e" command destroys it before reading the

-

2 -

Introduction to 'Ed'
As a matter of convenience, 'ed' re'uembers the file name specified on the last" e" command, so you do not have to specify a file name on the Ow" command. With these provisions, a
common editing session looks like
] ed
e file
{editing}

w
q
The "file" command ("f")
the name, just type:

is available for finding out the remembered file name.

To print out

f

file
You might also want to check that
] ed file
is exactly the same as
ed
e file
That is,

'ed' performs an "e" command for you if you give it a file name on the command line.

Errors - the Query command
Occasionally, an error of some ki~d is encountered.
Usually, these are caused by mis'ed'
spelled file names, although there are other possibilities. Whenever an error .occurs,
types
?

Although this
is rather cryptic, it is usually clear what caused the problem. If you need
further explanation, just enter "?" and 'ed' responds with a one-line explanation of the
error.
For example, if the last command you typed was an "e" command, 'ed' is probably saying that it could not find the file you asked for.
You can find out for sure by entering
It?" :

e myfile
?
?
I can't open the file to read

Except for
the messages in reponse to "?", 'ed' rarely gives other, more verbose error messages; if you should see one of these, t~e best course of action is to report it to whoever
maintains the editor at your installation.
Printing text - the Print command
You are likely to need to print t:1e text you have typed to check it for accuracy.
The
"print" command "p" is available to do t:1is.
"P" is different from the commands seen thus
far; "e", "w", and "a" have been seen to work on the whole buffer at once.
For a small file,
it might be easiest to print the entire buffer just to check on some few lines, but for very
large files this is clearly impractical.
The "p" command therefore accepts "line numbers"
that indicate which lines to print.
Try the following experiment:

1 ed file
3
lp
The quick brown fox
3p
the lazy dog.
1,2p
The quick brown fox
jumps over
1,3p
The quick brown fox
jumps over
the lazy dog.

- 3 -

Introduction to 'Ed'
"lp"
tells 'ed' to print line 1 ("The quick brown fox").
"3p" says to print the third line
("the lazy dog.").
"1,2p" tells 'ed' to print the first through the second lines, and "1,3p"
says to print the first through the third lines.
is.

Suppose we want to pr int the last 1 ine in the bl'ffer, but we don't know what its
'Ed' provides an abbreviation to specify the last line in the buffer:

number

$p
the lazy dog.
The dollar sign can be used just like a number.
type:

To print everything in the buffer, we could

l,$p
The quick brown fox
jumps over
the lazy dog.
If for some reason you want to stop the printing before it is done, press the BREAK key
on your terminal.
If you receive no response from BREAK, 'ed' is waiting for you to enter a
command. Otherwise, 'ed' responds with
?

and waits for your next command.
More Complicated Line Numbers
'Ed' has several ways to specify lines other than just numbers and "$".
ing command:

Try the follow-

p

the lazy dog.
'Ed'
ned
line
did
'Ed'

prints the last 1 ine. Does 'ed' always print the last line when it is given an unadorThe "current"
No.
The "p" command by itself prints the "current" line.
command?
is the last line you have edited in any way.
(Ps a matter of fact, the
last thing we
was to print all the lines in the buffer, so the last line was edited by being printed. )
allows you to use the symbol " "
(read "dot") to represent the current line. Thus
lip"

.

•p

the lazy dog.
is the same as

• ,.p
the lazy dog.
which is the same as just
p

the lazy dog.
II

"

can be used in many ways.

For example,

1,2p
The quick brown fox
jumps over
1, .p
The quick brown fox
jumps over
.,$p
jumps over
the la zy dog.
This example shows how to print all the lines up to the current line (l,.p) or all the lines
from the current line to the end of the buffer (.,$p).
If for some reason you would like to
know the 'number of the current line, you can type
3

and 'ed' displays the number.

(Note that the last thing we did was to print the

- 4 -

last

line,

Introduction to 'Ed'
so the current line became line 3.)
is not particularly useful when used alone.
" "
used in "line-number expressions." Try this experiment:

It becomes much more important when

.-lp
jumps over
"._1" means "the line that is one line before the current line."
.+lp
the lazy dog.
".+1" means "the line that is one line after the current line."
.-2,.-lp
The quick brown fox
jumps over
".-2,.-lp" means "print the lines from two lines before to one line before the current line."
You can also use "$" in line-number expressions:
$-lp
jumps over
"$-lp" means "print the line that is one line before the last line in the buffer,
next to the last line."

i.e.,

the

Some abbreviations are available to help reduce the amount of typing you have to do.
Typing a newline by itself is equivalent to typing ".+lp"; typing a caret, "A", followed by a
newline is equivalent to typing ".-lp"; and typing a line-number expression followed by a
newline is equivalent to typing that line-number expression followed by "p".
Examples:
{type a newline by itself}
the la zy dog.
Jumps over
I

The quick brown fox
It might be worthwhile to note here that almost all commands expect line numbers of one
form or another.
If none are supplied, 'ed' uses default values. Thus,
w file
is equivalent to
l,$w file
and

a
is equivalent to
.a

(which means, append text after the current line.)
Deleting Lines
As yet, you have seen no way of removing lines that are no longer wanted or needed.
do this, use the "delete" command "d":

To

1,2d
deletes the first through the second lines.
"D" expects line numbers that work in the same
way as those specified for Up", deleting one line or any range of lines.
d

deletes only the current line.

It is the same as ".d" or ".,.d".

-

5 -

Introduction to 'Ed'
After a deletion, the current line pointer is left pointing to the first line after the
group of deleted lines, unless the last line in the buffer was deleted.
In this-case, the
current line is the last line before the group of deleted lines.
Text Patterns
Frequently it is desirable to be able to find a particular "pattern" in a piece of text.
For example, suppose that after proofreading a report you have typed in using 'ed' you find a
spelling error. There must be an easy way to find the misspelled word in the file so it can
be corrected.
One way to do this is to count all the lines up to the line containing the
error, so that you can give the line number of the offending line to 'ed'.
Obviously, this
way is not very fast or efficient.
'Ed' allows you to "search" for patterns of text (like
words) by enclosing the pattern in slashes:
/juBlpS/
jumps over
'Ed' looks for the pattern you specified, and moves to the first line which contains the pattern. Note that if we had typed
/jumped/
?

'ed' would inform us that it could not find the pattern we wanted.
'Ed' searches forward from the current line when it attempts to find the pattern you
specified.
If
'ed'
reaches the last line without seeing the pattern, it "wraps around" to
the first line in the file and contin~es searching until it either finds the pattern or gets
back to ·the line where it started (line "."). This procedure ensures that you get the "next"
occurrence of the pattern you. were looking for, and that you don't miss any occurrences
because of your current position in the file.
Suppose, however, that you do not wish to find the "next" occurrence of a word, b'ut the
previous one instead. Very few text editors provide this capability; however, 'ed' makes it
simple. Just surround the pattern with backslashes:
\quick\
The quick brown fox
Remember: backslashes search backward. The backward search (or backscan, as i t i s sometimes
called) wraps around the file in a manner similar to the forward search (or scan).
The
search begins at the line before the current line, proceeds until the first line of the file
is seen, then begins at the last line of the file and searches up until the current line is
encountered. Once again, this is to ensure that you do not miss any occurrences of a pattern
due to your current position in the file.
'Ed' also provides more powerful pattern matching services than simply looking for a
given string of characters.
(A note to beginning users: this section may seem fairly complicated at first, and indeed you do not really need to understand it completely for effective use of the editor. However, the results you might get from some patterns would be
mystifying if you were not provided with some explanation, so look this over once and move
on. )
The pattern that may appear within slashes (or backslashes) is called a "regular expression."
It contains characters to look for and special characters used to perform other
operations. The following characters
%

?

$

*

@

have special meaning to 'ed':
%

Beginning of. line. The "%" character appearing as the first element in a pattern
matches the beginning of a line.
It is most frequently used to locate lines with
some string at the very beginning; for example,
/%The/
finds the next line that begins with the word "The". The percent sign has its
special meaning only!f it is the first element of the pattern; otherwise, it is
treated as a literal percent sign.

?

Any character. The question mark "?" in a regular expression matches ~ character (except a beginning-of-line or a newline).
It can be used like this:

- 6 -

Introduction to 'Ed'
/a?b/
to find strings like
a+b
a-b
a b
arbitrary
However, n?"
$

is most often used with the "closure" operator "*" (see below).

End of line.
The dollar sign appearing as the last element of
the newline character at the end of a line. Thus,

a

pattern

matches

/today$/
can be used to find a line with the word ntoday" at the very end. Like the percent
sign, the dollar sign has no special meaning in positions other than the end of a
pattern.
[]

Character classes.
For example,

The square brackets are used to match "classes" of

characters.

/[A-Z 11

finds the next line containing a capital letter,
/%[abcxyz]/
finds the next line beginning with an a, b, c, x, y, or z, and
/ [-0-9] /

finds the next line which contains a non-digit.
frequently used with the "closure" operator n*"

*

Character classes are also

Closure. The asterisk is used to mean "any number of repetitions (including zero)
of the previous pattern element (one character or a character class in brackets).n
Thus,
/a?*b/
finds lines containing an "an followed by any number of characters and a "b".
example, the following lines are matched:

For

ab
abnormal
Recording Media, by Dr. Joseph P. Gunchy
As another example,
/%=*$/
matches only those lines containing all equal-signs (or nothing at all).
wish to ensure that only non-empty lines are matched, use

If you

/%==*$/
Always remember that "*" (closure) matches zero or more repetitions of an element.
@

Escape. The "at" sign has special meaning to 'ed'.
It is the nescape" character,
which is used to prevent interpretation of a special character which follows.
SupYou may use the folpose you wish to locate a line containing the string "a * bU.
lowing command:
/a @* b/
The "at" sign "turns off" the special meaning of the asterisk, so it can be used as
an ordinary text character.
You may have occasion to escape any of the regular
expression metacharacters (%, ?, $, [, *, @, or {) or the slash itself. For exampIe, suppose you wi shed to find the next occur renee of the str ing "1/2". The command you need is:
/1@/2/

- 7 -

Introduction to 'Ed'
{}

Pattern tags. As seen in the next section, it is sometimes useful to remember what
part of a line was actually matched by a pattern. By default, the string matched
by the entire pattern is remembered.
It is also possible to remember a string that
was matched by only a part of a pattern by enclosing that part of the pattern in
braces. Hence to find the next line that contains a quoted string and remember the
text between the quotes, we might use

I" { ?*} " I
If the line thus located looked like this
This is a line containing a "quoted string".
then the text remembered as matching the tagged part of the pattern would be
quoted string
The last important thing you need to know about patterns is the use of the "default"
pattern.
'Ed'
remembers the last pattern used in any command, to save you the trouble of
retyping it. To access the remembered pattern, simply use an "empty" string.
For example,
the following sequence of commands could be used to step through a file, looking for each
occurrence of the string "ICS":

IICSI
II

II

(and so on)

One last comment before leaving pattern searching.

The constructs

Ipatternl
\pattern\
are not separate commands; they are components of line number expressions.
the line after the next line containing "tape", you could say

Thus,

to

print

I tap"'e/+ lp
Or,
to print a range of lines from one before to one after a line with a given pattern, you
could use
Ipattern/-I,/pattern/+lp

Making Substitutions - the Substitute command
This is one of the most used editor commands. The "substitute" command "s" is used
make small changes within lines, without retyping them completely.
It is used like this:

to

starting-line,ending-line s Ipattern/new-stuffl
For instance, suppose our buffer looks like this:
l,$p
The quick brown fox
.jumps over
the lazy dog.
To change "jumps" to "jumped,"
2s/jumps/jumped/p
jumped over
Note the use of the trailing "pH to print the result.
If the "p" had been omitted, the
change would have been performed (in the buffer) but the changed line would not have been
printed out.
If the last string specified in the substitute command is empty, then the text matching
the pattern is deleted:

- 8 -

Introduction to 'Ed'
s/jumped//p
over
s/t */
jumps /p
jumps over
Recalling that a missing pattern means "use the last pattern specified," try to explain
the following commands do:

what

s///p
jumps over

s//

/p
jumps over

(Note that, like many other commands, the substitute command assumes you want to work on the
current line if you do not specify any line numbers.)
What if you want to change "over" into "over and over"?

You might use

slover/over and over/p
jumps over and over
to accomplish this. There is a shorthand notation for this kind of substitution that was
alluded to briefly in the last section.
(Recall the discussion of "tagged" paterns.)
By
default, the part of a line that was matched by the whole pattern is remembered. This string
can then be included in the replacement string by typing an ampersand ("&")
in the desired
position. So, instead of the command in the last example,
s/over/& and

&1

could have been used to get the same result. If a portion of the pattern had been tagged,
the text matched by the tagged part in the replacement could be reused by typing "@l":
s/jump{?*}/vault@l/p
vaults over and over
It is possible to tag up to nine parts of a pattern using braces.
tagged part may then be used in a replacement string by typing

The text matched

by

each

@n
where n corresponds to the nth "{" in the pattern.

What does the following command do?

s/{[- ]*} {?*}/@2 @l/
Final words on substitute: the slashes are known as "delimiters" and may be replaced by
any other character except a newline, as long as the same character is used consistently
throughout the command. Thus,
s'vaults'vaulted'p
vaulted over and over
is legal. Also, note that substi~ute changes only the first occurrence of the pattern that
it finds; i f you wish to change all occurrences on a line, you may append a "g" (for
"global") to the command, like this:

sl /*/gp
****vaulted*over*and*over
Line Changes and Insertions
Two "abbreviation" commands are available to shorten common operations applying to
changes of entire lines. These are the "change" command "c" and the "insert" command nino
The change command is a combination of delete and append.

Its format is

starting-line,ending-line c
This command deletes the given range of lines, and then goes into append mode to obtain text
to replace them. Append mode works exactly the same way as it does for the "a" command;
input is terminated by a period standing alone on a line. Examine the following editing session to see how change might be used:

- 9 -

Introduction to 'Ed'
l,$c
Ed is an interactive program used for
the creation and modification of -text.

c
the creation and modification of -text. w
-Text" may be any collection of character
data.
As you can see, the current line is set to the last line entered in append mode.
The other abbreviation command is "i".
following relation holds:

"I" is very closely related to "a"; in fact, the

starting-line
is the same as
starting-line - 1
In short, "i"· inserts
specified line.

a

text

before the specified line, whereas "a" inserts text after the

Moving Text
Th roughout this guide, we have concentrated on what may be called "in-place"
The other type of editing commonly used is often called "cut-and-paste" editing.
command "m" is provided to facilitate this kind of editing, and works like this:

editing.
The move

starting-line,ending-line m after-this-line
If you wanted to move the last fifty lines of a file to a point after
command would be

the

third

line,

the

$-49,$m3
Any of the line numbers may, of course, be full expressions with search strings, arithmetic,
etc.
You may, if you like, append a "p" to the move command to cause it
line moved.
The current line is set to the last line moved.

to

print

the

last

Global Commands
The "global" command "g"
is
buffer that match a certain pattern.
"editor", you could type

used to perform an editing command on all lines in the
For example, to print all the lines containing the word

g/editor/p
If you wanted to correct some common spelling error, you would use
g/old-stuff/s//new-stuff/gp
which makes the change in all appropriate lines and prints the resulting lines.
example: deleting all lines that begin with an asterisk could be done this way:

Another

g/%@*/d
"G" has a companion command "x" (for "exclude") that performs an operation on all lines
in the buffer that do not match a given pattern.
For example, to delete all
lines that do
not begin with an asterISk, use
x/%@*/d
"G" and "x" are very powerful commands that are essential for advanced usage, but are
usually not necessary for beginners. Concentrate on other aspects of 'ed' before you move on
to tackle global commands.

- 10 -

Introduction to 'Ed'
Marking Lines
During some types of editing, especially when moving blocks of text, it is often necessary to refer to a line in the buffer that is far away from the current line. For instance,
say you want to move a subroutine near the beginning of a file to somewhere near the end, but
you areh't sure that you can specify patterns to properly locate the subroutine. one way to
solve this problem is to find the first line of the subroutine, then use the co.mmand 11.-":
/subroutine/
subroutine think

.=

47
and write
thing:

down

(or remember) line 47.

Then find the end of the subroutine and do the same

/end/
end

.=

71

Now you move to where you want to place the subroutine and enter the command
47,71m.
which does exactly what you want.
The problem here is that absolute line numbers are easily forgotten, easily mistyped,
and difficult to find in the first place. It is much easier to have 'ed' remember a short
"name" along with each line, and allow you to reference a line by its name. In practice, it
seems convenient to restrict names to a single character, such as "b" or "e" (for "beginning"
or "end").
It is not necessary for a given name to be uniquely associated with one line;
many lines may bear the same name. In fact, at the beginning of the editing session, all
lines are marked with the same name: a single space.
To
return to our. example, us ing the 'k' command, we can mark the beg inning and ending
lines of the subroutine quite easily:

/subroutine/
subroutine think
kb
/end/
end
ke
We have now marked the first line in the subroutine with "b" and the second line with "e".
Both
To refer to names, we need more line number expression elements:
">" and "<".
work in line number expressions just like "$" or "/pattern/". The symbol ">" followed by a
single character mark name means "the line number of the first line with this name when you
search forward".
The symbol "<" followed by a single character mark name means "the line
number of the first line with this name when you search backward".
(Just remember that ,<,
points backward and ,>, points forward.)
Now in our example, once we locate the new destination of the subroutine, we can use
"
or
se -t  myfile
Again, if you are using the an ADDS Regent 100 terminal, you could type

1 se -t regent
Use of the third method depends on how your installation is set up and is usually practical only when terminals are directly connected to the computer, or are all of the same
model.
If this is the case in your installation, as it is at Georgia Tech, you can use the
'e' command to invoke 'se' with the proper terminal type. All you need do is type
e myfile
and 'se' will appear.
Using • Se'
Once 'se' knows your terminal type, it clears the screen, draws in its margins, and
begins reading your file (if you specified one).
The screen it draws looks something like
this.
(The parenthesized numerals are not part of the screen layout, but are there to aid in
the following discussion.)

- 14 -

Introduction to 'Ed'

(1)

(2)
(3 )
1
integer a
*1
c
1
-> 1
for (a = 1; a <= 12; a = a + 1)
E
call putch (NEWLINE, STDOUT)
1
F
stop
1
$
end
1
(4 )
cmd>
11: 39 myfile •••• (5) ••••••••••••••••••••••••••••••••••

A
B

The display is divided into five parts:
(1) the line number area, (2) the mark name area,
(3) the text area, (4) the command line, and (5) the status line. The current line (remember
In addition, a
" • n)
is indicated by the symbol "." in the 1 ine number area of the screen.
rocket ("->") is displayed to make the current line more obvious. The current mark name of
Other
each line is shown in the markname area just to the left of the vertical bar.
information, such as the number of lines read in, the name of the file, and the time of day,
are displayed in the status line.
The cursor is positioned at the beginning of the command line, showing you that 'se'
awaits your command.
You may now enter any of the 'ed' commands and 'se' will perform them,
while making sure that the current line is always displayed on the screen. There are only a
few other things that you need know to successfully use 'se'.
'Se' always recognizes BS (control-h) and DEL as the erase and
regardless of your Subsystem erase and kill character settings.

kill

characters,

If you make an error, 'se' displays an error message in the status line (you need
not request it).
It also leaves your command line intact so that you may change it
using in-line editing commands (we'll get to this a little later).
If you don't
want to bother with changing the command, just hit DEL and 'se' will erase it.
The "po command has a different meaning than in 'ed'. When used with line numbers,
it displays as many of the lines in the specified range as possible (always including the last line).
When used wi thout line numbers, "p" displays the previous
page.
The ":" command positions a specified line at the top of the screen
(e.g.,
"12:"
positions the screen so that line 12 is at the top).
If no line number is
specified, ":" displays the next page.
The "v" command can be use to modify an entire line rather than just add to the end
of it. Also, if you use "v" over a range of lines and find you want to terminate
the command before all lines have been considered, the control-f key is used
instead of a period.
Keeping these few differences in mind, you will see that 'se' can perform all of the funtions
of 'ed', while giving the advantage of a "window" into the edit buffer.
Extended Line Numbers
'Se' has a number of features that take advantage of the window display to minimize
keystrokes and speed editing.
In the line number area of the screen, 'se' always displays
for each line a string that may be used in a command to refer to that line.
Normally,
it
displays a capital letter for each line, but in "absolute line number" mode (controlled by
the Roan command; see the section on options for more details), it displays the ordinal number of the line in the buffer.
The line number letters displayed by 'se' may be used in any context requiring a line
number.
For instance, in the above example, a change to the first line on the screen could
be specified as
As/%/* my new program/
You could delete the line before the first line on the screen by typing
A-Id

Case Conversion
When
'se' is displaying upper-case letters for line numbers, it accepts command letters
only in lower case. For those who edit predominately upper-case text this is somewhat inconvenient; for those with upper-case only terminals this is a disaster.
For this reason,
'se'
- 15 -

Introduction to 'Ed'
offers several options to alleviate this situation.
First of all,
typing a control-z causes 'se' to invert the case of all letters (just
like the alpha-lock key on some terminals).
Upper-case letters are converted to lower-case,
lower-case letters are converted to upper-case, and all other characters are unchanged.
You
can type control-z at any time to toggle the case conversion mode. When case inversion is in
effect, 'se' displays the word "CASE" in the status line.
One drawback to this feature is that 'se' still expects line numbers in upper case and
commands in lower case, so you must shift to type the command letter -- just the reverse of
what you're used to.
A more satisfactory solution is to specify the "c" option. Just type
oc
on the command line and 'se' toggles the case conversion mode, and completely reverses its
interpretation of upper and lower case letters.
In this mode, 'se' displays the line number
letters in lower case and expects its command I-etters in upper case.
Unshifted letters from
the terminal are converted to upper case and shifted letters to lower case.
Tabs
In the absence of tabs, program indentation is very costly in keystrokes.
So 'se' gives
you the ability to set arbitrary tab stops using the not" command.
By default, 'se' places a
stop at column 1 and every third column thereafter.
Tabs corresponding to the default can be
set by enumerating the column positions for the stops:
ot 1 4 7 10 13 16 19 22 25 28 31 34
This
is almost as bad as typing the blanks on each line.
shorthand for such repetitive specifications.

For this reason, there is also a

ot +3
sets a tab stop at column 1 and at every third column thereafter.
prefer the specification

Fortran

programmers

may

ot 7 +3
to set a stop at column 7 and at every third thereafter.
Once the tab stops are set, the control-i and control-e keys can be used to move the
cursor from its current position forward or backward to the nearest stop, respectively.
Full-Screen Editing
Full screen editing with 'se' is accomplished through the use of control characters for
editing
functions.
A few,
such as control-h, control-i, and control-e have already been
mentioned.
Since 'se' supports such a large number of control functions, the mnemonic value
of control character assignments has dwindled to almost zero.
About the only thing mnemonic
is that most symmetric functions have been assigned to opposing keys on the keyboard
(e.g.,
forward
and backward tab to control-i and control-e, forward and backward space to control-g
and control-h, skip right and left to control-o and control-w, and so on). We feel pangs of
conscience about this, but can find no more satisfactory alternative.
If you feel the
control character aSSignments are terrible and you can find a better way, you may change them
by modifying the definitions in 'se' and recompiling.
If they work well, we'd like to hear
about them.
Except for a few special purpose ones, control characters can be used anywhere, even on
the command line.
(This is why erroneous commands are not erased -- you may want to edit
them.)
Most of the functions work on a single line, but in overlay mode (controlled by the
"v" command) the cursor may be positioned anywhere in the buffer.
Horizontal Cursor Motion
There are quite a few functions for moving the cursor. You've probably used at least
one
(control-h) to backspace over errors.
None of the cursor motion functions erase characters, so you may move forward and backward over a line without destroying
it.
Here are
several of the more frequently used cursor motion characters:
control-q

Move forward one column.

- 16 -

Introduction to 'Ed'
control-h

Move backward one col umn.

control-i

Move forward to the next tab stop.

control-e

Move backward to the previous tab stop.

control-o

Move to the first col umn beyond the end of the line.

control-w

Move to column 1.

Vertical Cursor Motion
'Se' provides two control keys, control-d and control-k, to move the cursor up and down,
respectively,
from line to line through the edit buffer. The exact function of each depends
on 'se's current mode:
in command mode they simply move the current line pointer without
affecting the cursor position or the contents of the command line; in overlay mode (viz. the
"vO command)
they actually move the cursor up or down one line within the same column;
finally, in append move, these keys are ignored. Regardless of the mode,· the screen is
adjusted when necessary to insure that the current line is displayed.
control-d

Move the cursor up one line.

control-k

Move the cursor down one line.

Character Insertion
Of course the next question is:
"Now that I've moved the cursor, how do I change
things?"
If you want to retype a character, just position the cursor over it, and type the
desired character; the old one is reptaced. You may also insert characters at the current
cursor position instead of merely overwriting what's already. there.
Typing a control-c
inserts a single blank before the character under the cursor and moves the remainder of the
line one column to the right; the cursor remains in the same column over the newly-inserted
blank.
Typing a control-x inserts enough blanks at the current cursor position to move the
character that was there to the next tab stop. This can be handy for . aligning items in a
table, for example. As with control-c, the cursor remains in the same column.
A more general way of handling insertions is to.type control-a. This toggles "insert
mode" -- the word "INSERT" appears on the status line, and all characters typed from this
point are inserted in the line
(and characters to the right are moved over). Typing
control-a again turns insert mode off. Here is a summary of these control characters:
control-a

Toggle insert mode.

control-c

Insert a blank to the left of the cursor.

control-x

Insert blanks to the next tab stop.

Character Deletion
There are many ways to do away with characters. The most drastic is to type DEL;
'se'
erases the current line and leaves the cursor in column 1. Typing control-t causes 'se' to
delete the character under the cursor and all those to its right. The cursor is left in the
same column which is now just beyond the new end of the line. Similarly, control-y deletes
all the characters to the left of the cursor (not including the one under it). The remainder
of the line is moved to the left, leaving the cursor over the same character, but now in
column 1.
Control-r deletes the character under the cursor and closes the gap from the
right, while control-u does the same thing after first moving the cursor one column to the
left. These last two are most commonly used to eat characters out of the middle of a line~
DEL

Erase the entire line.

control-t

Erase the characters under and to the right of the cursor.

control-y

Erase the characters to the left of the cursor.

control-r

Erase the character under

control-u

Erase the character immediately to left of the cursor.

th~

cursor.

- 17 -

Introduction to 'Ed'
Terminating a Line

After you have edited a line, there are two ways of terminating it (having it entered or
executed) •
The most commonly used is newline (or carriage-return) which deletes all characters under and to the right of the cursor and terminates the line.
To terminate a line
without deleting any characters, there is control-v.
NEWLINE

Erase characters under and to the right of the cursor and terminate.

control-v

Terminate.

Non-printing Characters

'Se' displays a non-printing character as a blank (or other user-selectable character;
see the description of noun in the section on options).
Non-printing characters
(such as
'se's control characters), or any others for that matter, may be entered by hitting the ESC
key followed immediately by the key to generate the desired character. Note, however, that
the character you type is taken literally, exactly as it is generated by your terminal, so
case conversion does not apply.
ESC

Accept the literal value of the next character, regardless of its function.

- 18 -

Introduction to 'Ed'
Screen Editor Options
Options for 'se' can be specified in two ways: with the "0" command or on the Subsystem
command line that invokes 'se'. To specify an option with the "0" command, just enter ·0"
followed immediately by the option letter and its parameters. To specify an option on the
command line, just use "-" followed by the option letter and its parameters.
With this
second method, if there are imbedded spaces in the parameter list, the entire option should
be enclosed in quotes. For example, to specify the "a" (absolute line number) option and t'ab
stops at column 8 and every fourth thereafter with the "0" command, just enter
oa
ot 8 +4
when 'se' is waiting for a command.
you might use

To enter the same options on the invoking command

line,

se -t regent myfile -a "-t 8 +4"
The following table summarizes the available 'se' options:
Option

Action

a

causes absolute line numbers to be displayed in the line number area of the screen.
The default behavior is to display upper-case letters with the letter "A"
corresponding to the first line in the window.

c

inverts the case of all letters you type (i.e., converts upper-case to lower-case
and vice versa). This option causes commands to be recognized only in upper-case
and alphabetic line numbers to be displayed and recognized only in lower-case.

d[]

selects the placement of the current line pointer following a "d" (delete) command.
 must be either ">" or "<". If ">" is specified, the default behavior is
selected:
the line following the deleted lines becomes the new current line. If
"<" is specified, the line immediately preceding the deleted lines becomes the new
current line. If neither is specified, the current value of  is displayed 'in
the status line.

f

selects Fortran oriented options.
and "t7 +3" (see below) options.

1 []

sets the line number display option.
Under control of this option, , se'
continuously displays the value of one of three symbolic line numbers.
 may
be any of the following:

*
$

This is equivalent to specifying

both

the

nco

display the current line number
display the number of the top line on the screen
display the number of the last line in the buffer

If  is omitted, the line number display is disabled.
t[] sets

tab

stops according to .
 consists of a s,eries of numbers
columns in which tab stops are to be set. If a number is preceded by a
plus SIgn ("+"), it indicates that the number is an increment~ stops are set at
regular intervals separated by that many columns, beginning with the most recently
specified absolute column number. If no such number precedes the first increment
specification, the stops are set relative to column 1. By default, tab stops are
set in every third column starting with column 1, correspondin~ to a 
specification of "+3". If  is omitted, the current tab spacing IS displayed
in the status line.
indicat~ng

u[]

selects the character that 'se' displays in place of unprintable characters. 
may be any printable character; it is initially set to blank. If  is omitted,
'se' displays the current replacement character on the status line.

v[]

sets the default "overlay column".
This is the column at which the cursor is
initially positioned by the "v" command.  must be a positive integer, or a
dollar sign ($) to indicate the end of the line. If  is omitted, the current
overlay column is displayed in the status line.

- 19 -

Introduction to 'Ed'
w[]

sets the "warning threshold" to  which must be a positive integer.
Whenever
the cursor is positioned at or beyond this column, the column number is displayed
in the status line and the terminal's bell is sounded.
If  is omitted, the
current warning threshold is displayed in the status line. The default warning
threshold is 74, corresponding to the first column beyond the right edge of the
screen on an 80 column crt.

-[]

splits the screen at the line specified by  which must be a simple line number
within the current window. All lines above  remain frozen on the screen, the
line specified by  is replaced by a row of dashes, and the space below this
row becomes the new window on the file.
Further editing commands do not affect the
lines displayed in the top part of the screen.
If  is omitted, the screen is
restored to its full size.

- 20 -

Introduction to 'Ed'
Screen Editor Control Characters
Character Action
control-a Toggle insert mode. The status of the insertion indicator is inverted.
Insert
mode, when enabled, causes characters typed to be inserted at the current cursor
position in the line instead of overwriting the characters that were there
previously. When insert mode is in effect, ·INSERT" appears in the status line.
control-b Scan right and erase. The current line is scanned from the current cursor position
to the right marg in until an occurrence of the next character type.d is found. When
the character is found, all characters from the current cursor position up to (but
not including) the scanned character are deleted and the remainder of the line is
moved to the left to close the gap. The cursor is left in the same column which is
now occupied by the scanned character. If the line to the right of the cursor does
not contain the character being sought, the terminal's bell is sounded. 'Se'
remembers the last character that was scanned using this or any of the other scanning keys; if control-b is hit twice in a row, this remembered character is used
instead of a literal control-b.
control-c Insert blank. The charac·ters at and to the right of the current cursor position
are moved to the right one column and a blank is inserted to fill the gap.
control-d Cursor up. The effect of this key depends on 'se's current mode. When in command
mode, the current line pointer is moved to the previous line without affecting the
contents of the command line. If the current line pointer is at line 1, the last
line in the file becomes the new current line. In overlay mode (viz. the "v" command), the cursor is moved up one line while remaining in the same column.
In
append mode, this key is ignored.
control-e Tab left.
position.

The cursor is moved to the nearest tab stop to the left of its current

control-f "Funny" return. The effect of this key depends on the editor's current mode.
In
command mode, the current command line is entered as-is, but is not erased upon
completion of the command; in append mode, the current line is duplicated; in overlay mode (viz. the ·v· command), the current line is restored to its original
state and command mode is reentered (except if under control of a global prefix).
control-g Cursor. right.

The cursor is moved one column to the right.

control-h Cursor left. The cursor is moved one column to the left.
erase any characters; it simply moves the cursor.
control-i Tab right.
position.

Note that this does not

The cursor is moved to the next tab stop to the right

of

its

current

control-k Cursor down.
As with the control-d key, this key's effect depends on the current
editing mode. In command mode, the current line pointer is moved to the next line
without changing the contents of the command line. If the current line pointer is
at the last line in the file, line 1 becomes the new current line.
In overlay mode
(viz. the ·v" command), the cursor is moved down one line while remaining in the
same column. In append mode, control-K has no effect.
control-l Scan left.
The cursor is positioned according to the character typed immediately
after the control-I. In effect, the current line is scanned, starting from the
current cursor position and moving left, for the first occurrence of this character. If none is found before the beginning of the line is reached, the sqap
resumes with the last character in the line. If the line does not contain the
character being looked for, the message nNOT FOUND n is printed in the status line.
'Se' remembers the last character that was scanned for using this key; if the
control-l is hit twice in a row, this remembered character is searched for instead
of a literal control-I.
Apart from this, however, the character typed after
control-l is taken literally, so 'se's case conversion feature does not apply.
control-m Newline.

This key is identical to the NEWLINE key described below.

control-n Scan left and erase. The current line is scanned from the current cursor position
to the left margin until an occurrence of the next character typed is found. Then
that character and all characters to its right up to (but not including) the
character under the cursor are erased. The remainder of the line, as well as the
cursor are moved to the left to close the gap. If the line to the left of the cursor does not contain the character being sought, the terminal's bell is sounded.
As with the control-b key, iE control-n is hit twice in a row, the last character
- 21 -

Introduction to 'Ed'
scanned for is used instead of a literal control-no
control-o Skip right.
line •.

The cursor is moved to the first position beyond the

current

end

of

control-p Interrupt.
If executing any command except "a", "c", "i" or "v", 'se' aborts the
command and reenters command mode. The command line is not erased.
control-q Fix screen.
screen.

The screen is reconstructed from 'se's internal representation of

the

control-r Erase right.
The character at the current cursor position is erased and all
characters to its right are moved left one position.
control-s Scan right. This key is identical to the control-l key described above,
that the scan proceeds to the right from the current cursor position.
control-t Kill right.
The
right are erased.

character

at

except

the current cursor position and all those to its

control-u Erase left. The character to the left of the current cursor position is deleted
and all characters to its right are moved to the left to fill the gap. The cursor
is also moved left one column, leaving it over the same character.
control-v Skip right and terminate.
line is terminated.
control-w Skip left.

The cursor is moved to the current end of line

and

the

The cursor is positioned at column 1.

control-x Insert tab.
The character under the cursor is moved right to the next tab stop;
the gap is filled with blanks. The cursor is not moved.
control-y Kill left. All characters to the left of the cursor are erased; those at and to
the right of the cursor are moved to the left to fill the void.
The cursor is left
in column 1.
control-z Toggle case conversion mode.
The status of the case conversion indicator is
inverted; if case inversion was on, it is turned off, and vice versa. Case inversion, when in effect, causes all upper case letters to be converted to lower case,
and all lower case letters to be converted to upper case. Note, however, that 'se'
continues to recognize alphabetic line numbers in upper case only, in contrast to
the "case inversion" option (see the description. of options above). When case
inversion is on, "CASE" appears in the status line.
Insert newline.
A newline character is inserted before the current cursor
position, and the cursor is moved one position to the right. The newline is
displayed according to the current non-printing replacement character (see the "un
option) •

control-

control-\ Tab left and erase.
Characters are erased starting with the character at the
nearest tab stop to the left of the cursor up to but not including the character
under the cursor. The rest of the line, including the cursor, is moved to the left
to close the gap.
.
control-

A

Tab right and erase. Characters are erased starting with the character under the
cursor up to but not including the character at the nearest tab stop to the right
of the cursor. The rest of the line is then shifted to the left to close the gap.

NEWLINE

Kill right and terminate. The characters at and to the right of the current cursor
pOSition are deleted, and the line is terminated.

DEL

Kill all.
The entire line is erased, along with any error message that appears in
the status line.

ESC

Escape. The ESC key provides a means for entering 'se's control characters
literally as text into the file.
In fact, any character that can be generated from
the keyboard is taken literally when it immediately follows the ESC key.
If the
character is non-printing (as are all of 'se's control characters), it appears on
the screen as the current non-printing replacement character (normally a blank).

- '22 -

Introduction to 'Ed'
Bditor Command Summary
Syntax

Function

a[:text]

Append
Inserts text after the specified line. Text is inserted until a line
In 'se', if
containing only a period and a newline is encountered.
the command is followed immediately by a colon, then whatever text
follows the colon is inserted without entering "append" mode. The
current line pointer is left at the last line inserted.

·, .

c [:tex t]

Change
Deletes the lines specified and inserts text to replace them.
Text
is inserted until a line containing only a period and a newline is
encountered. In 'se', if the command is followed immediately by a
colon, then whatever text follows the colon is inserted without
entering "append" mode. The current line pointer is left at the last
line inserted.

·, .

d[p]

Delete
Deletes all lines between the specified lines, inclusive.
The
current line pointer is left a the line after the last one deleted.
If the "p" is included, the new current line is printed.

none

e [filename]

Enter
Loads the specified file into the buffer and prepares for editing.
Automatically invoked if a filename is specified as an argument on
the command line used to invoke the editor. The current line pointer
is positioned at the first line in the buffer.

none

f [filename]

File
Print or change the remembered file name. If a name is given, the
remembered file name is set to that value; otherwise, the remembered
file name is printed.

•,$

g/pat/command

Global on pattern
Performs the given command on all lines in the specified
match a certain pattern.

none

h [stuff]

Help
In
'se', provides access to online documentation on the screen
is
editor.
"Stuff" may be used to select which information
displayed.

i [: tex t]

Insert
Inserts text before the specified line. Text is inserted until a
line containing only a period and a newline is encountered.
In 'se',
if the command is immediately followed by a colon, then whatever text
follows is inserted without entering "append" mode. The current line
pointer is left at the last line inserted.

j/stuff![p]

Join
The specified lines are joined into a single line. The newlines that
previously separated the lines are replaced by "stuff".
If the .p"
option is used, the resulting line (which becomes the new current
line) is printed.

·, .

kc

marK
The specified lines are marked with 'c'
which may be any single
character other than a newline.
If 'c' is not present, the lines are
marked with the default name of blank. The current line pointer is
never changed.

·, .

m [p]

Move
Moves the specified block of lines after .  [p]

copY
Makes a copy of all the lines in the given range, and inserts the
copies after .
As with the "m" command,  may not be
omitted. The current line pointer is set to the new copy of the last
line in the range; this line is printed if the "ph is present.

=[p]

Equals
The number of the specified line is printed. The line itself is also
printed if the "pH option is used. The current line pointer is not
changed.

none

?

Query
In 'ed' only, a verbose description of the last error encountered is
pr inted.

1,$

Iccommand

Exclude on markname
Similar to the 'x' prefix except that 'command' is performed for
lines in the range that do not have the mark name 'c'.

-

24 -

lines in the given range that do not

all

Introduction to 'Ed'

1,$

'ccommand

Global on markname
Similar to the 'g' prefix except that 'command' is performed for all
lines in the range that have the mark name 'c'.
Print next page
In 'ed', 23 lines beginning with the current line are printed
(equivalent to ".,.+23pn).
In 'se', the next page of the buffer is
displayed and the current line pointer is placed at the top of the
window.

- 25 -

Introduction to 'Ed'
Elements of Line Number Expressions
Form

Value

integer

value of the integer (e.g., 44).
number of the current line in the buffer.

$

number of the last line in the buffer.
number of the previous line in the buffer (same as .-1).

Ipatternl

number

of

the

next line in the buffer that matches the given pattern (e.g.,
wraps around
to the beginning and back to the current line.

IFebruary/)i the search proceeds to the end of the buffer, then
\pattern\

>name

number of the previous line in the buffer that matches the given pattern
(e.g., \JanuarY\)i search proceeds in reverse, from the current line to line
1, then from the last line back to the current line.
number

of

the next line having the given markname (search wraps around, like

II) •
]

Matches any single character that is a member of the set specified by .
 may be composed of single characters or of character ranges of the form
-.
If character ranges are used,  and  must both belong to
the digits, the upper case alphabet or the lower case alphabet.
Matches
.

any

single

character

that

is not a member of the set specified by

*

In combination with the immediately preceeding pattern element,
or more characters that are matched by that element.

@

Turns off the special meaning of the immediately following character.
character has no special meaning, this is treated as a literal "@".

{}

Tags the
text actually matched by the sub-pattern specifed by  for
use in the replacement part of a substitute command.

&

Appearing in the replacement part of a substitute command, represents the text
actually matched by the pattern part of the command.

@

Appearing in the replacement part of a substitute command, represents the text
actually matched by the tagged sub-pattern specified by .

- 26 -

matches

zero

If that

User's Guide for the
Software Tools Subsystem Command Interpreter
(The Shell)

II
T. Allen Ak in
Perry B. Fl inn
Daniel H. Forsyth, Jr.

School of Information and Computer Science
Georgia Institute of Technology
Atlanta, Georgia
30332
April, 1980

TABLE OF CONTENTS

Tutorial ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••• •.•••••
Getting· Started •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••.•
Typographical Conventions •••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Commands . . . . . . . . . . . . . . . . . . . . . . . . . . ~ • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • • •

Special Characters and Quoting ••••••••••••••••••••••••••••••••••••••••••••••••••••
Command Fi les •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Doing Repetitive Tasks --- Iteration ••••••••••••••••••••••••••••••••••••••••••••••
Sources and Destinations of Data ••••••••••••••••••••••••••••••••••••••••••••••••••
Pipes and Networ ks ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Compound Nodes ••••••••••••••••••••••••• ,...........................................
Function Calls ••••••••••••••••••••••••••••••••• •.••••••••••••••••••••••••••••••••••
Variables •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Conel usion ........................................................... ... .. • . . . . • . . .
Summary of Syntax and Semantics •••••••••••••••••••••••••••••••••••••••••.••••••••••••
Commands

••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

1
1
1
1
1
2
2
3
4
5
5
6
6
7
7

Networks. •.••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

7

Nodes

•••..•••.••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

9

Comments ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Variables •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Iteration •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Function Calls ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Concl usion ••••••••••••••••••••••••••.•••••••••••••••••••••••••••••••••••••••••••••

12
12
12
13
13

Application Notes ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Basic Functions •••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Shell Control Variables •••••••••••••.••••••••••• •.•••••••••••••••••••••••••••••••••
Symbiotic Commands ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Argument Fetching ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••
Shell Tracing .....................••....•.•••••..•••••••••.•••••...•.••.•..•..•
Shell Variable Utilities •••••••••••••••••••••••••••••••••••••••••••••••••••••••
Concl usion ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

14
14
16
17
17
18
18
18

Messages from the Shell ••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••••

19

iii

Introduction
The Software Tools
Software Tools by Brian W.
on the Prime 400 computer
The present Subsystem, the
of computing resources.

Subsystem is a set
Kernighan and P. J.
in 1977 and 1978 in
seventh version, is

of program development tools based on the book
Plauger.
It was originally developed for use
the form of several cooperating user programs.
a powerful tool that aids in the effective use

The command interpreter, also referred to as the "shell," is a vital part of the Subsystem.
It is a program which accepts commands typed by the user on his terminal and converts them into more primitive directions to the computer itself.
The user's instructions
are expressed in a special medium called the "command language." The greatest part of this
document is involved with describing the command language and giving examples of how it is
used.
Three areas will be covered in the following pages.
First, there is a tutorial on the
use of the command language. New Subsystem users should read this chapter first.
Some
minimal knowledge of terminal usage is assumed; if you are unsure of yourself in this area,
see Prime's published documentation and the Software Tools Subsystem Tutorial for help.
Second,
there is a summary of the syntax and semantics of the command language. Experienced
users should find this chapter valuable as a reference.
Finally, there is a selection of
application notes.
This chapter is a good source of useful techniques and samples of
advanced usage.
Experienced users and curious beginners should find it well worthwhile.

- iv -

Command Interpreter User's Guide
Tutorial
Getting Started
After you have logged in to the computer, you must start up the Subsystem.
type the command "swt":

To do

this,

OK, swt
]

The Subsystem
bracket.

fires

up and the command interpreter prompts you for input by typing a right

Typographical Conventions
The rules for correcting typographical errors under the Subsystem may be different from
the usual ones on your system.
(You can change the rules, if you like; see the Subsystem
Tutorial for more information.)
Usually, the Subsystem expects a backspace (control-h) to be
used for deleting single characters that are in error, and a DEL (RUBOUT on some terminals)
to delete entire lines that are in error.
Throughout this chapter, references will be made to input lines that are terminated with
a "newline." You should use the "newline" key on a terminal only if it lacks a "return" key.
They do not necessarily have the same effect.
Commands
Input to the command interpreter consists of "commands." Commands, in turn, consist of
a "command name,"
usually made up of letters and digits, and additional pieces of
information, often called "parameters" or "arguments."
(Note that a command mayor may not
have arguments, depending on its function.)
The command name and any arguments are separated
from each other by spaces.
For example:
] echo Bello world!
Bello world!
]

The command name is "echo".
'Echo' is not a very involved command; it simply types back
parameters, whatever they may be.

its

Here is another command, one that is a bit more useful:

]If
adventure
shell
words

ee
shell.doc
zunde

guide
subsys

m680D

time sheet

]

'Lf'
is used to list the names of your files.
('Lf' may be used with arguments, as well as
without them; for more information, see the Software Tools Subsystem Reference Manual, or try
typing the command nhelp If".)
Special Characters and Quoting
Some characters have special meanin'J to the command interpreter.
ing this command:

For example, try

typ-

] echo Alas, poor Yorick
Alas
poor: not found
]

This strange behavior is caused by the fact that the comma is used for dark mysterious
purposes elsewhere in the command language.
(The comma actually represents a null I/O connection between nodes of a network.
See the section on pipes and networks for more
information.)
In fact, all of the following characters are potential troublemakers:

It

*

@

>

blank

The way to handle this problem is to use quotes.

You may use either single or double quotes,

Command Interpreter User's Guide
but be sure to match each with another of the same kind.

Try this command now:

echo -Alas, poor Yorick; I knew him well."
Alas, poor Yorick; I knew him well.
]

You can use quotes to enclose other quotes:
] echo 'Quoth the raven: -Nevermore!"
Quoth the raven: "Nevermore!"
]

A final word on quoting: Note
argument.
For example, the command

that

anything

enclosed

in

quotes

becomes

a

single

] echo "Can I use that in my book?"
has only one argument, but
echo Can I use that in my book?
has seven.
Command Files
Suppose you have a task which must be done often enough that it is inconvenient to
remember the necessary commands and type them in every time. For an example, let's say that
you have to print the year-end financial reports for the last five years.
If the "print"
command is used to print files, your command might look like:
] print year74 year75 year76 year77 year78 year79
If you use a text editor to make a file named "reports" that contains this command,
then print your reports by typing

you

can

reports
No special command is required to perform the operations in this "command file;" simply typing its name is sufficient.
Any number of commands may be placed in a command file.
It is possible to set up groups
of commands to be repea~ed or executed only if certain conditions occur.
See the
Applications Notes for examples.
It is one of the important features of the command interpreter that command files can be
treated exactly like ordinary commands.
As shown in later sections, they are actually
programs written in the command language; in fact, they are often called "shell programs."
Many Subsystem commands ('e', 'fos', and 'rfl', for example) are implemented in this manner.
Doing Repetitive Tasks --- Iteration
Some commands can accept only a single argument. One example of this is the 'fos' command. "Fos" stands for "format, overstrike, and spool."
It is a shorthand command for
printing "formatted" documents on the line printer.
(A "formatted" document is one prepared
with the help of a program called a "text formatter," which justifies right margins,
indents
paragraphs, etc. This document was prepared by the Software Tools text formatter 'fmt.') If
you have several documents to be prepared, it is inconvenient to have to type the 'fos' command for each one.
A special technique called "iteration" allows you to "factor out" the
repeated text.
For example,
]

fos (filel file2 file3)

is equivalent to
fos filel
fos file2
fos file3
The arguments inside the parentheses form an "iteration group."
There may be more than one
iteration group in a command, but they must all contain the same number of arguments. This
is because each new command line produced by iteration must have one argument from each
group.
As an illustration of this,

- 2 -

Command Interpreter User's Guide
(echo print fos) f1le(1 2 3)
is equivalent to
] echo filel
1 print file2
] fos file3
Iteration is performed by simple text substitution; if there is no space between an argument
and an iteration group in the original command, then there is none between the argument and
group elements in the new commands. Thus,
file(l 2 3)
is equivalent to
f ilel
fi Ie 2
file3
Iteration is most useful when combined with function calls, which will be discussed later.
Sources and Destinations of Data
Control of the sources and destinations of data is a very basic function of the command
interpreter, yet one that deserves speci31 attention. The concepts involved are not new, yet
they are rarely employed to the extent that they have been used in the SUbsystem.
The best
approach to learning these ideas is to experiment.
Get on a terminal, enter the Subsystem,
and try the examples given here until th-=y seem to make sense. Above all, experiment freely;
try anything that comes to mind.
The Subsystem has been designed with the idea that users
are intelligent human beings, and their freedom of expression is the most valuable of tools.
Use your imagination; if it needs tweaking, take a look at the Application Notes in the last
chapter.
Every program and command in the Subsystem can gather data from certain well-known
places and deliver it to other well-known places.
Data sources are known as "standard input
ports;" data des·tinations are called "standard output ports." Programs are said to "read
from standard input" and "write on standClrd output."
The key point here is that programs
need not take
into account how input data is made available or what happens to output data
when they are finished with it; the commClnd interpreter is in complete control of the standard ports.
A command we will use frequently in this section is 'copy'.
'Copy' does exactly what
its name implies; it copies data from one place to another.
In fact, it copies data from its
first standard input port to its first standard output port.
The first point to remember is that by default, standard ports reference
Try 'copy' now:

the

terminal.

copy
After you have entered this command, type some random text followed by a newline.
'Copy'
will type the same text back to you.
(When you tire of this game,
type a control-c; this
causes an end-of-file signal to be sent to
'copy', which then returns to the command
interpreter. Typing control-c to cause end-of-file is a convention observed by all Subsystem
programs.)
Since you did not say otherwise, standard input and standard output referred to
the terminal;
input data was taken from the terminal (as you typed it) and output data was
placed on the terminal (printed by 'copy').
Obviously, 'copy' would not be of much use if this was all it could do.
Fortunately,
the command interpreter can change the sources and destinations of data, thus making 'copy'
less trivial.
Standard ports may be altered so as to refer to disk files by use of a "funnel."
The
greater-than sign
(»
is used to represent a funnel.
Conventionally, the ">" points in the
direction of data flow.
For example, if you wished to copy the contents of file "ee" to file
"old_ee", you could type
] ee>

*

copy

>old ee

The greater-than sign must always be imm,~diately next to its associated filename;
no
intervening blanks are allowed. At least one blank must separate the '>' from any command name or
arguments.
This restriction is necessary to insure that the command language can be
interpreted unambiguously.

- 3 -

Command Interpreter User's Guide
The construct "ee>" is read "from ee"; ">old ee" is read "toward old ee."
Thus, the
command above can be read" from ee copy toward old ee," or, "copy from ee toward old ee."
The process of changing the file assignment of a standard port by use of a funnel is called
"I/O redirection," or simply "redirection."
It is not necessary to redirect both standard input and standard output; either may be
redirected independently of the other.
For example,
ee>

copy

can be used to print the contents of file nee" on the terminal.
(Remember that standard output, since it was not specifically redirected, refers to the terminal.)
Not surprisingly,
the last variation of 'copy',

1 copy

>old ee

is also useful.
This command causes input to be taken from the terminal (until an end-offile is.generated by typing a control-c) and placed on the file "old ee". This is a quick
way of creating a small file of text without using a text editor.
It is important to realize that all Subsystem programs behave uniformly with regard to
redirection.
It is as correct to redirect the output of, say, 'If'
If

>file list

as it is to redirect the output of 'copy'.
Although the discussion has been limited to one input port and one output port up to
this point, more of each type are available.
In the current implementation, there are a
total of six; three for input and three for output.
The highest-numbered output port is
generally used for error messages, and is often called "ERROUT"; you can "capture" error messages by redirecting this output port. For example, if any errors are detected by 'If' in
this command
1 If
then

th~

3>errors

resulting error messages will be placed on the file "errors".

Final words on redirection:
there are two special-purpose redirection operators left.
They are both represented by the double funnel "»~". The first operator is called "append:"

1 1f

»list

causes a list of files to be placed at the end of (appended to) the file named "list". The
second operator is called "from comman~input~ It is represented as just "»" with no file
name, and causes standard input to refer to the current source of commands.
It is useful for
running programs like the text editor from "scripts" of instructions placed in a command
file.
Pipes and Networks
The last section discussed I/O redirection, the process of making standard ports refer
to disk files, rather than just to the terminal.
This section will take that idea one step
further.
Frequently, the output of one program is placed on a file, only to be picked up
again later and used by another program. The command interpreter simplifies this process by
eliminating the intermediate file.
The connection between programs that is so formed is called a "pipe," and a linear array of programs communicating through pipes is called a
"pipeline."
.
Suppose that you maintain a large directory, containing drafts of various manuals. Each
draft is in a file with a name of the form "MANxxxx.rr", where "xxxx" is the number of the
manual and "rr" is the revision number. You are asked to produce a list of the numbers of
all manuals at the first revision stage. The following command will do the job:
If -c I find .01
"If -cor lists the names of all files in the current directory. The "pipe connection"
(vertical bar) causes this listing to be passed to the 'find' command, which selects those
lines containing the string ".01" and prints them. Thus, the pipeline above will print all
filenames matching the conventional form of a first-revision manual name.
The ability to build special purpose commands cheaply and quickly from available tools
using pipes is one of the most valuable features of the command interpreter. With practice,
surprisingly difficult problems can be solved with ease. For further examples of pipelines,
see the Applications Notes.
-

4 -

Command Interpreter User's Guide
Combinations of programs connected with pipes need not be linear. Since multiple standard ports are available, programs can be and often are connected in non-linear networks.
(Some networks cannot be executed iE the programs in the network are not executed
concurrently. The command interpreter detects such networks, and prints a warning message if
they cannot be performed.)
Further information on networks can be found in both the
reference and applications chapters of this Guide.
Compound Nodes
It is sometimes necessary to change the standard port environment of many commands at
one time, for reasons of convenience or efficiency. The "compound node" (a set of networks
surrounded by curly braces) can be used in these situations.
As an example of the first case, suppose that you wish to generate a list of manual
names (see the last example) in either the first or the second stage of revision. One way to
do this is to generate the list for the first revision stage, place it on a file using a funnel, then generate a list for the second revision stage and place it on the end of the same
file using an "append" redirector. A compound node might simplify the procedure thusly:
] { If -c I find .01;

If -c I find .02}

>list

The first network finds all manuals at the first reVISIon stage, and the second finds all
those at the second stage. The networks will execute left-to-right, with the output of each
being placed on the file "list," thus generating the desired listing. With iteration, the
command can be collapsed even farther:
] { If -c I find .0(1 2) }
This combination of iteration and

>list

compou~d

nodes is often useful.

Efficiency becomes a consideration in cases where successive long streams of data are to
be copied onto a file; if the "append" redirector is used each time, the file must be
reopened and repositioned several times.
Using a compound node, the output file need be
opened only once:
] { (filel file2 file3»

copy}

>all files

This complex exa~ple copies the contents of files "filel," "file2," and "file3" into the file
named "all files."
Function Calls
Programs in the Subsystem r'eceive information through their command-line arguments as
well as their standard ports, so it is s,)metimes useful to deliver the output of a program to
the command interpreter for further processing, rather than to a pipe. The "function call"
mechanism is available for this purpose. For example, recall the situation illustrated in
the section on pipes and networks; suppose it is necessary to actually print the manuals
whose names were found.
This is how the task could be done:
print [If -c I find .01]
The function call is composed of the pipeline "If -c I find
.01" and the square brackets
enclosing it.
The output of the pipeline within the brackets is passed to 'print' as a set
of arguments, which it accesses in the usual manner. Specifically, all the lines of output
from the pipeline are combined into one set of arguments, with spaces provided where multiple
lines have been collapsed into one line.
'Print' accepts multiple arguments; however, suppose it was necessary to use a program
like '£OSl, that accepts only one argument.
Iteration can be combined with a function call
to do the job:
] fos ([If -c I find .01])
This command
"01" •

formats

and prints all manuals in the current directory with revision numbers

Function calls are frequently us~d in command files, particularly for accessing
arguments passed to them. Since the sequence "1 f -c I find pattern" occurs very f requentl y,
it is a good candidate for replacement with a command file; it is only necessary to pass the
pattern to be matched from the argument list of the command file to the 'find' command with a
function call. The following command file, called 'files', will illustrate the process:
1 f -c I find [arg 1]

- 5 -

Co~and

Interpreter User's Guide

"arg 1" retrieves the first command file
argument to 'find' through its argument list.
network was appropriate:

argument. The function call then passes that
'Files' may then be used anywhere the original

files .01
print [files .01]
fos ([files .01])

Variables
It has been claimed that the command language is a programming language in its own
right.
One facet of this language that has not been discussed thus far is the use of its
variables. The command interpreter allows the user to create variables, with scope, and
assign values to them or reference the values stored in them.
Certain special variables
These variables have names
which is the prompt string the
object to ")" as a prompt, you

are used by the command interpreter in its everyday operation.
that begin with the underline ( ).
One of these is ' prompt',
command interpreter prints when-requesting a command.- If you
can change it with the "set" command:

1 set prompt = "OK, "
OK, set prompt = -, "
% set prompt
"] "
1

-

You may create and use variables of your own. To create a variable in the current scope
(level of command file execution), use the "declare" comand:
) declare i j k sum
Values are assigned to variables with the 'set' command. The command interpreter checks the
current scope and all surrounding scopes for the variable to be set; if found, it is changed,
otherwise it is declared in the current scope and assigned the specified value.
Variables behave like small programs that print their current values. Thus the value of
a variable can be obtained by simply typing its name, or it can be used in a command line by
enclosing it in brackets to form a function call.
The following command file
(which also
illustrates the use of 'if', 'eval', and 'goto') will count from 1 to the number given as its
first argument:
declare i
set i
1
: loop
if (eval i ">"
goto exit
fi

(arg 1))

set i = (eval i + 1)
goto loop
:exit
Note the use of the "eval" function, which treats its arguments as an arithmetic expression
and returns the expression's value.
This is required to i~sure that the string "i + 1" is
interpreted as an expression rather than as a character string. Also note that 'fi'
terminates the 'if' command.
Conclusion
This concludes the tutorial chapter of this document. Despite the fact that a good deal
of material has been presented, much detail has been omitted.
The next chapter is a complete
summary of the capabilities of the command interpreter.
It is written in a rather technical
style, and is recommended for reference rather than self-teaching. The last chapter is a set
of examples that may prove helpful. As always, the best approach is simply to sit down at a
terminal and tryout whatever you wish to do.
Should you have difficulty, further tutorials
are available, and the 'help' command can be consulted for quick reference.

- 6 -

Command Interpreter User's Guide
Summary of Syntax and Semantics
This section is the definitive document for the syntax and corresponding semantics of
the Software Tools Subsystem Command Interpreter. It is composed of several sub-sections,
each covering some major area of command syntax, with discussions of the semantic
consequences of employing particular constructs. It is not intended as a tutorial, nor is it
intended to supply multitudinous examples; the other sections of this document are provided
to fill those needs.
Commands
 ::= [ 

r ;

 } ] 

The ncommand" is the basic unit of communication between the command interpreter and the
user.
It consists of any number of networks (described below) separated by semicolons and
terminated by a newline. The networks are executed one at a time, left-to-right; should an
error occur at any point in the parse or execution of a network, the remainder of the
 is ignored. The null command is legal, and causes no action.

*

The command interpreter reads commands for interpretation from the "command source. n
This is initially the user's terminal, although execution of a commarid file may change the
assignment. Whenever the command source is the terminal, and the command interpreter is
ready for input, it prompts the user with the string contained in the shell variable
'prompt'. Since this variable may be altered by the user, the prompt string is selectable
on a per-user basis.
Networks
 ::= 
{  {  }  }
 ::=
 ::=

, I  1 'I' [ 1 [ . ]

 ::= 
 ::=  I $ I