This chapter discusses the advanced capabilities of the shell. In
addition to basic command line processing, the shell facilitates:
You can use these advanced capabilities in many combinations.
Following are several examples. Study the basic rules, use your
imagination, and explore.
The shell is a program that reads and processes command lines,
one at a time, from the computer's input device (usually your
keyboard). It parses (scans) each line to identify and process any
of the following parts that might be present:
For some commands, only the keyword (the program, procedure
file, or command name) must be present. Other commands have
required or optional parameters. As well, a command line can
include modifiers that influence the operation of the command.
OS-9 features that affect command execution are:
Once the shell identifies the keyword, it processes any modifiers.
It then assumes the remaining text consists of parameters,
which it passes to the program being called.
When the shell receives a built-in command, it immediately exe
cutes it. If it receives a command that is not built in, it searches
for the appropriate program and then runs it as a new process.
The keyword must be the first entry in any line.
While the program is running, the shell deactivates itself. At the
termination of the program, the shell reactivates and accepts the
next input. This cycle continues until the shell detects an end-of
file in the input path. It then terminates its own execution. You
can input an end of file from the keyboard by pressing
SHIFT BREAK .
Following is a sample shell command line that calls the
assembler.
Add command modifiers to a command line to change the way in
which the command functions. Modifiers let you tailor OS-9 com
mands to your specifications. Type them in a command line after
the keyword and either before or after other parameters you
might be using.
The shell processes command modifiers before it executes a pro
gram. If it detects an error in any of the modifiers, it stops exe
cution and reports the error.
The shell strips command modifiers from the part(s) of the com
mand line passed to the program as parameters. Therefore, you
cannot use the characters reserved as modifiers ( # ; ! < > & )
inside other parameters.
Execution modifiers alter the amount of memory commands have
available, or they redirect command input or output.
Alternate Memory Size Modifier. When the shell invokes a
command program, it allocates the minimum amount of working
RAM (random access memory) specified in the program's module
header.
You might want to increase a command's default memory size.
You can assign memory either in 256-byte pages or in 1024-byte
increments. To add memory in pages, use the modifier #n, where
n is the number of pages. To add memory in 1024-byte incre
ments, use the modifier #nK, where n is the number of 1024
byte increments.
I/O Redirection Modifiers. Input/output redirection modifiers
reroute a program's I/O from the standard path to alternate files
or devices.~.~One of OS-9's advantages is that its programs use standard I/O
paths rather than individual, specific file, or device names. You
can easily redirect the I/O to any file or device without altering
the program itself.
Programs that normally receive input from a terminal or send
output to a terminal use one or more of these three standard I/O
paths:
When you use a redirection modifier in a command line, follow it
immediately with a pathlist for the substitute device. For exam
ple, you can use LIST to redirect the contents of a file called
Correspondence from the terminal to the printer, by typing:
The shell automatically creates, opens, and closes files referenced
by redirection modifiers as needed. The system immediately
restores normal I/O paths at the completion of any com
mand using redirection modifiers.
In the next example, the shell redirects DIR's output-a list of
files in the MEMOS directory-to the file /D1/Savelisting:
OS-9 displays the file contents in a format similar to a directory
listing.
You can use one or more redirection modifiers before the pro
gram's parameters, after the program's parameters, or both.
However, use each modifier only once in a command.
The following example shows how you can use all of the redirec
tion modifiers together to start BASIC09 on a device window and
redirect all input and output to it:
When you redirect multiple paths, you must use the redirection
symbols in the proper order as shown here:
Command Separators. You can include more than one com
mand on a command line by using command separators. Com
mand separators cause multiple commands to execute either
sequentially or concurrently, depending on the separator you
use.
Sequential execution means that one program must complete its
function and terminate before the shell lets the next program
execute. Concurrent execution means that two or more programs
begin execution and run simultaneously.
Sequential Execution Using the Semicolon. Using a semi
colon between commands on one line causes them to execute
sequentially. For instance:
This command causes the shell to: (1) execute the COPY com
mand, (2) enter a waiting state until COPY terminates, then
awake, and (3) execute DIR.
If an error occurs in any program, the shell does not execute
subsequent commands, regardless of the state of the SHELL
command's X (stop on error) option.
Commands separated by semicolons are in fact separate and
equal child processes of the shell.
Concurrent Execution Using the Ampersand. You can use
the ampersand (&) to cause multiple commands to run at the
same time. Each command you specify runs as a separate child
process of the shell. That is, for each process, the shell creates a
separate shell to handle the operation. When the process is com
plete, the child shell terminates, or dies.
While more than one process is running, OS-9 divides execution
time equally among the processes.
The number of programs that can run at the same time varies.
It depends on the amount of free memory in the system and the
memory requirements of the programs being executed.
The shell begins to run DIR, sending output to the printer. At
the same time it displays both the number of the forked process
DIR) and a new prompt, like this:
To fork a process means to create a process as a branch of
another process-a subroutine.
After using the ampersand to fork a background process, you
can then enter another command, which the shell executes while
output from your original command continues to go to the
printer. This means you don't waste time waiting for OS-9 to fin
ish a task. At times, the keyboard might not seem to respond to
your typing, because characters do not appear on the screen.
However, OS-9 stores the characters in the keyboard buffer and
displays them as soon as the shell can accept input again.
If you have several processes running simultaneously and want
information about them, use the PROCS command.
Combining Sequential and Concurrent Executions. You can,
if you want, use both the concurrent and sequential command
separators in one command line. For example:
Because the & modifier joins the DIR, LIST, and COPY com
mands, these commands run concurrently. But, because a semi
colon precedes the DEL command, DEL does not run until the
other commands terminate.
Using Pipes: The Exclamation Mark. You can use the excla
mation mark (!) to construct pipelines for OS-9 commands. Pipe
lines consist of two or more concurrently executing programs
with standard input paths, and standard output paths or both,
connected to each other with pipes.
Pipes are the primary means of transferring data from process
to process. They are vital to interprocess communications. Pipes
are first-in, first-out buffers, or holding areas for data.
The shell automatically buffers and synchronizes 1/O transfers
using pipes. A single pipe can direct data to several destinations
or readers, and can receive data from several sources, or writers
on a first-come, first-serve basis. An end-of-file occurs if a pro
gram attempts to read from a pipe when writers are not avail
able to send data. Conversely, a write error occurs if a program
attempts to write to a pipe when readers are not available.
Pipelines are created by the shell when it processes an input line
with one or more pipe separators (!). For each pipe separator, the
shell directs the standard output of the program on the left of
the pipe separator to the standard input of the program on the
right of the separator. The shell creates an individual pipe for
each pipe separator in the command line. For example:
This command redirects input from a path called Master-file to
a file named Update. The output of Update becomes the input for
the program Sort. The output of Sort, in turn, becomes the input
for the program Write-report. Finally, the command redirects
output from Write-report to the printer. The shell executes all
programs in a pipeline concurrently. The pipes synchronize the
programs so the output of one never gets ahead of the input
request of the next program. This synchronization means that
data cannot flow through a pipeline any faster than the slowest
program can process it.
Raw Disk Input/Output. OS-9 has a special pathlist function
to perform raw physical input/output operations on a disk. The
pathlist consists of the device name, immediately followed by the
character.
This command causes OS-9 to treat the entire diskette in Drive
/DO as one logical file. The operation reads each byte of each sec
tor, without regard to actual file structure. Commands such as
DIR, ATTR, and MFREE use this feature to access sectors of
disks that are not part of file data areas, such as header sectors.
To convert a byte address to a logical sector number when using
@, multiply the sector number by 256. Conversely, the logical
sector number of a byte address is the byte address, modulo 256.
You can enclose sections of command lines in parentheses to per
mit modifiers and separators to affect an entire set of programs.
The shell processes the material in the parentheses by recur
sively calling itself to execute the enclosed command list.
For example, if you want to send directory listings of the ROOT
directory of Drive /DO and then the ROOT directory of Drive /D1
to the printer, you can type either:
The results are identical except that the system keeps the printer
continuously in the second example. In the first example, another
user could steal the printer between DIR commands.
You can group commands to cause programs to execute both
sequentially and concurrently with respect to the shell that ini
tiated them. For instance:
Here, the shell does the overall deleting process concurrently
with whatever else you tell it to do, because you're using &.
However, the shell deletes the three specified files sequentially
because you're using semicolons within the parentheses.
Suppose you have a program named Makeuppercase that con
verts lowercase characters to uppercase and a program named
Transmit that sends data to another computer, you can use a
command line like this:
The shell processes the output of the first DIR command and
then the second. It sends all the DIR output to Makeuppercase,
and Transmit sends all the output to another computer.
The shell is a re-entrant program. This means it can be simulta
neously executed by more than one process. Like most other OS
9 programs, the shell uses standard I/O paths for routine input
and output.
OS-9's shell offers you a special feature, a time and effort saver
called a procedure file. A procedure file is a related group of
commands, and when you run the file, you execute all the
commands.
Other names for procedure file processing are batch and back
ground processing. A procedure file becomes new input for the
shell. By running a procedure file, you're using the shell to cre
ate a new shell, a subshell that accepts and carries out the com
mands in the procedure file.
When you enter any command line, the shell looks for the speci
fied program in memory or in the execution directory. If it can
not find the program there, it searches the data directory for a
file with the specified name. If it finds the file, the shell auto
matically interprets it as a procedure file, and creates the sub
shell, which executes the commands listed in the procedure file.
Procedure files can also let the computer execute a lengthy
series of programs while it is unattended, or even while it is run
ning other programs.
There are two ways to run a procedure file. For instance, to exe
cute a procedure file called Mailsequence, type either:
Both commands do the same thing: create a subshell to run the
commands you've built into your Mailsequence procedure file.
To run a procedure file in a concurrent mode, use the ampersand
(&) modifier. As long as memory is available, you can run any
number of files concurrently.
You can even build procedure files to sequentially or concurrently
execute other procedure files.
The shell has a number of built-in commands and options.
Whenever you use one of these functions, the shell executes it
without loading it or creating a new process to execute it.
You can execute built-in functions alone, use them at the begin
ning of a command line, or use them following any program sep
arator. You can separate adjacent built-in commands by spaces
or commas.