## Shell Procedure Files

The shell is a reentrant program that can be simultaneously executed by more than one process at a time. As is the case with most other OS-9 programs, it uses standard I/O paths for routine input and output. specifically, it requests command lines from the standard input path and writes its prompts and other data to the standard error path.

The shell can start up another process also running the shell by means of the shell command. If the standard input path is redirected to a mass storage file, the new “incarnation” of the shell can accept and execute command lines from the file instead of a terminal keyboard. The text file to be processed is called a “procedure file”. It contains one or more command lines that are identical to command lines that are manually entered from the keyboard. This technique is sometimes called “batch” or “background” processing.

If the `program name` specified on a shell command line can not be found in memory or in the execution directory, shell will search the data directory for a file with the desired name. If one is found, shell will automatically execute it as a procedure file.

Execution of procedure files have a number of valuable applications. It can eliminate repetitive manual entry of commonly-used sequences of commands. It can allow the computer to execute a lengthy series of programs “in the background” while the computer is unattended or while the user is running other programs “in the foreground”.

In addition to redirecting the shell's standard input to a procedure file, the standard output and standard error output can be redirected to another file which can record output for later review or printing. This can also eliminate the sometimes-annoying output of shell messages to your terminal at random times.

Here are two simple ways to use the shell to create another shell:

    OS9: shell <procfile

    OS9: procfile

Both do exactly the same thing: execute the commands of the file `procfile`. To run the procedure file in a “background” mode you simply add the ampersand operator:

    OS9: procfile&

OS-9 does not have any constraints on the number of jobs that can be simultaneously executed as long as there is memory available. Also, the procedure files can themselves cause sequential or concurrent execution of additional procedure files. Here's a more complex example of initiating two processing streams with redirection of each shell's output to files:

    OS9: proc1 T >>stat1& proc2 T >>stat2&

Note that the built-in command “T” (copy input lines to error output) was used above. They make the output file contain a record of all lines executed, but without useless “OS9” prompts intermixed. The “-x” built-in command can be used if you do not want processing to stop if an error occurs. Note that the built-in commands only affect the shell that executes them, and not any others that may exist.