Advanced Features of the Shell


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.


More About Command Line Processing

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:


Execution Let you increase the amount of random access
Modifiers memory (RAM) available for a command. Also
lets you redirect input to a process, output from
a process, or both.
Command Let you enter more than one command on a line,
Separators perform concurrent execution of commands, or
connect the input or output of one command to
another command.
3-1
OS-9 Commands Reference

Command Lets you group all the commands that you want
Grouping affected by command modifiers or separators.

Note: The next section, "Command Modifiers," provides
details on these features.

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.


In this example:





asm sourcefile 1 -o >/p x12k

3-2


Command Modifiers

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

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.


Note: All executable programs include a module header
which holds the program's name, size, memory require
ments, and other information. For information on viewing
the contents of a module header, see the IDENT command.

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.


The following two examples have identical results:





OS-9 Commands Reference

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:


    Standard input path-Routes data from the terminal's

    keyboard to programs. The standard input path is Path

    Number 0.


      Use the less-than symbol (<) to redirect data to this

      path.


      Standard output path-Routes data from programs to

      the terminal's display. The standard output path is Path

      Number 1. --


      Use the greater-than symbol (>) to redirect data from

      this path.


      Standard error output path-Routes routine status

      messages (prompts and errors) to the terminal's display.

      (The name error output path is somewhat misleading,

      since many kinds of messages in addition to error mes

      sages travel the path.) The standard error path is Path

      Number 2.


      Use two greater-than symbols (») to redirect data

      from this path.


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:


    list correspondence >/P ENTER -


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.


3-4
                Advanced Features of the Shell / 3


In the next example, the shell redirects DIR's output-a list of

files in the MEMOS directory-to the file /D1/Savelisting:


    dir /d9/memos >/d1/savelisting ENTER


You can now view the contents of Savelisting by typing:

    list /d1/savelistin9 ENTER


OS-9 displays the file contents in a format similar to a directory

listing.


    Directory of /d9/memos

    CMDS SYS startup

    0S9Hoot


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:


    basic99 <»>/w1 ENTER


When you redirect multiple paths, you must use the redirection

symbols in the proper order as shown here:


    Legal Illegal


    <> /wl >< /wl

    <» /wl »< /wl

    »> /wl »< /w1


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.


                                3-5

OS-9 Commands Reference

Sequential Execution Using the Semicolon. Using a semi

colon between commands on one line causes them to execute

sequentially. For instance:


    copy myfile /d1/newfile; dir >/p ENTER


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.


Here are two more examples of commands using the semicolon:

    copy oldfile newfile; del oldfile; list newfile


    ENTER


    dir /d1/myfile; list temp >/p; del temp ENTER


Commands separated by semicolons are in fact separate and

equal child processes of the shell.


Note: When one process creates another process, OS-9 calls
the creator the parent process and the created process the
child process. The child can become a parent by creating
yet another process.

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.


An example of a simple command line using the & separator is:

    d i r > / p & ENTER


3-6
                Advanced Features of the Shell / 3


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:


    &ee7

    os9:


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:


    dir >/P& list file1& copy filet filet; del temp

    ENTER


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.


                                3-7

OS-9 Commands Reference

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:


    update <master-file ! sort ! write-report

    > / P ENTER


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.


Warning: When using this raw access, use extreme cau
tion. Because you can write on any sector, you can easily
damage file or directory structures and lose data. Using C
defeats any file security and record locking systems.

3-8
                Advanced Features of the Shell / 3


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.


Command Grouping

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:


    dir /d0 >/p; dir /d1 >/p ENTER


or:

    (dir /d9; dir /d1) >/p ENTER


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:


    (del filet ; del filet; del file3)& ENTER


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:


    (dir cmds; dir sys) ! makeuppercase ! transmit


    ENTER


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.


                                3-9

OS-9 Commands Reference

Shell Procedure Files

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.


Note: If you plan to use the same command sequences
repeatedly, create a procedure file to do the job by using
BUILD.

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:


    shell mailsequence ENTER


or

    mailsequence ENTER


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.


3-10
                Advanced Features of the Shell / 3


You can even build procedure files to sequentially or concurrently

execute other procedure files.


Note: If you use procedure files to run programs you don't
intend to monitor closely, you can redirect standard output
and standard error output to another file. Later you can
review the file's contents. Output redirection eliminates the
annoying output of shell messages on your terminal at ran
dom times.

Built-in Shell Commands and Options

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.


The built-in commands and their functions are:

          CHD pathlist Changes the data directory to the directory

              specified by the pathlist.


          CHX pathlist Changes the execution directory to the direc

              tory specified by the pathlist.


          EX modname Directly executes the module named. This

              function deletes the shell process so that it

              ceases to exist and executes the new module in

              its place. Use EX to replace the executing

              shell with the program specified by modname.

              You can also use EX without a module name

              to eliminate the current shell, for example, a

              shell you initialized in a window (see below).

i = devname Makes a shell an immortal shell. This means
that when the shell ends, due to an EOF, OS-9
restarts it. Each time the shell restarts, it has
the same data and execution directories. To
kill an immortal shell, use EX to "chain" to a
null process, such as:
e x ENTER
3-11
OS-9 Commands Reference

w Waits for any process to terminate.
* text Allows you to make a comment. The shell does
not process text following the asterisk. Use
this function to label operations in a procedure
file.
kill procID Stops the specified process.
setpr procID Changes the specified process's priority
number number.
x Causes the shell to cease operation whenever
an error occurs (a system default).
-x Causes the shell to continue operation when
an error occurs. Use this function in procedure
files to enable the shell to continue to other
commands if one command process fails
because of a system error.
p Turns the shell prompt and messages on (a
system default).
-p Inhibits the shell prompt and messages. Use
this option in procedure files to disable screen
display. Be sure to turn the prompt and mes
sage function back on afterward.
t Makes the shell copy all input lines to output.
Use this function with a procedure file to
cause command lines to display as they
execute.
-t Sets the system so that it does not copy input
lines to output (a system default).

Running Compiled Intermediate
Code Programs

Before the shell executes a program, it checks the program mod
ule's language type. If it is not 6809 machine language, the shell
calls the appropriate run-time system for that module.

3-12
                Advanced Features of the Shell / 3


For instance, if you have BASIC09 on your OS-9 system and
want to run a BASIC09 I-code module called Adventure, you can
type:

    basic09 adventure ENTER


or:

    adventure ENTER


or:

    runb adventure ENTER


In the last example, the shell uses the RUNB module to inter
pret the Adventure I-code module.

3-13