144
|
1 <chapter>
|
|
2 <title>Advanced Features of the Shell</title>
|
|
3 <para>
|
|
4 The basic shell functions were introduced in Section 2 in order
|
|
5 to provide an understanding of how basic OS-9 commands work. In
|
|
6 this section the more advanced capabilities of the shell are
|
|
7 discussed. In addition to basic command line processing, the shell
|
|
8 has functions that facilitate:
|
|
9 </para>
|
|
10
|
|
11 <itemizedlist mark="square">
|
|
12 <listitem><para>
|
|
13 I/O redirection (including filters)
|
|
14 </para></listitem>
|
|
15 <listitem><para>
|
|
16 Memory Allocation
|
|
17 </para></listitem>
|
|
18 <listitem><para>
|
|
19 Multitasking (concurrent execution)
|
|
20 </para></listitem>
|
|
21 <listitem><para>
|
|
22 Procedure File Execution (background processing)
|
|
23 </para></listitem>
|
|
24 <listitem><para>
|
|
25 Execution Control (built-in commands)
|
|
26 </para></listitem>
|
|
27 </itemizedlist>
|
|
28
|
|
29 <para>
|
|
30 There is a virtually unlimited combination of ways these
|
|
31 capabilities can be used, and it is impossible to give more than a
|
|
32 representative set of examples in this manual. You are therefore
|
|
33 encouraged to study the basic rules, use your imagination, and
|
|
34 explore the possibilities on your own.
|
|
35 </para>
|
|
36
|
|
37 <section>
|
|
38 <title>A More Detailed Description Command Line Processing</title>
|
|
39 <para>
|
|
40 The shell is a program that reads and processes command lines one
|
|
41 at a time from its input path (usually your keyboard). Each line is
|
|
42 first scanned (or "parsed") in order to identify and process any of
|
|
43 the following parts which may be present:
|
|
44 </para>
|
|
45
|
|
46 <itemizedlist mark="square">
|
|
47 <listitem><para>
|
|
48 A program, procedure file, or built-in command name ("verbs")
|
|
49 </para></listitem>
|
|
50 <listitem><para>
|
|
51 Parameters to be passed to the program
|
|
52 </para></listitem>
|
|
53 <listitem><para>
|
|
54 Execution modifiers to be processed by the shell
|
|
55 </para></listitem>
|
|
56 </itemizedlist>
|
|
57
|
|
58 <para>
|
|
59 Note that only the verb (the program or command name) need be
|
|
60 present, the other parts are optional. After the verb has been
|
|
61 identified, the shell processes modifiers (if any). Any other text
|
|
62 not yet processed is assumed to be parameters and passed to the program called.
|
|
63 </para>
|
|
64 <para>
|
|
65 Unless the verb is a "built-in command", the shell will run the
|
|
66 program named as a new process (task). It then deactivates itself
|
|
67 until the program called eventually terminates, at which time it
|
|
68 gets another input line, then the process is repeated. This happens
|
|
69 over and over until an end-of-file condition is detected on the
|
|
70 shell's input path which causes the shell to terminate its own
|
|
71 execution.
|
|
72 </para>
|
|
73 <para>
|
|
74 Here is a sample shell line which calls the assembler:
|
|
75 </para>
|
|
76 <screen>
|
|
77 asm sourcefile l -o >/p #12k
|
|
78 </screen>
|
|
79 <para>
|
|
80 In this example:
|
|
81 </para>
|
|
82
|
|
83 <informaltable frame="none">
|
|
84 <tgroup cols="2">
|
|
85 <colspec colwidth="2in">
|
|
86 <colspec colwidth="3in">
|
|
87 <tbody>
|
|
88 <row>
|
|
89 <entry>asm</entry>
|
|
90 <entry>is the verb</entry>
|
|
91 </row>
|
|
92 <row>
|
|
93 <entry>sourcefile l -o</entry>
|
|
94 <entry>are parameters passed to "asm</entry>
|
|
95 </row>
|
|
96 <row>
|
|
97 <entry>>/p</entry>
|
|
98 <entry>is a modifier which redirects the output
|
|
99 (listing) to the system's printer</entry>
|
|
100 </row>
|
|
101 <row>
|
|
102 <entry>#12K</entry>
|
|
103 <entry>is a modifier which requests that the
|
|
104 process be assigned 12K bytes of memory
|
|
105 instead of its (smaller) default amount.</entry>
|
|
106 </row>
|
|
107 </tbody>
|
|
108 </tgroup>
|
|
109 </informaltable>
|
|
110
|
|
111 <para>
|
|
112 The verb must be the first name in the command line. After it
|
|
113 has been scanned, the shell first checks if it is a "built-in"
|
|
114 command. If it is, it is immediately executed. Otherwise, the shell
|
|
115 assumes it is a program name and attempts to locate and execute it
|
|
116 as described in Sections 5.3 and 5.4.1.
|
|
117 </para>
|
|
118 </section>
|
|
119
|
|
120 <section>
|
|
121 <title>Execution Modifiers</title>
|
|
122 <para>
|
|
123 Execution modifiers are processed by the shell before the program
|
|
124 is run. If an error is detected in any of the modifiers, the run
|
|
125 will be aborted and the error reported. Characters which comprise
|
|
126 modifiers are stripped from the part(s) of the command line passed
|
|
127 to the program as parameters, therefore, the characters reserved for
|
|
128 use as modifiers ( # ; ! < > & ) cannot be used inside parameters,
|
|
129 but can be used before or after the parameters.
|
|
130 </para>
|
|
131
|
|
132 <section>
|
|
133 <title>Alternate Memory Size Modifier</title>
|
|
134 <para>
|
|
135 When command programs are invoked by the shell, they are
|
|
136 allocated the minimum amount of working RAM memory specified in the
|
|
137 program's module header. A module header is part of all executable
|
|
138 programs and holds the program's name, size, memory requirements,
|
|
139 etc. (See 5.4). Sometimes it is desirable to increase this default
|
|
140 memory size. Memory can be assigned in 256-byte pages using the
|
|
141 modifier "#n" where n is the decimal number of pages, or in 1024
|
|
142 byte increments using the modifier "#nK". The two examples below
|
|
143 behave identically:
|
|
144 </para>
|
|
145 <screen>
|
|
146 OS9: copy #8 file1 file2 (gives 8*256 = 2048 bytes)
|
|
147 OS9: copy #2K file1 file2 (gives 2*1024 = 2048 bytes)
|
|
148 </screen>
|
|
149 </section>
|
|
150
|
|
151 <section>
|
|
152 <title>I/O Redirection Modifiers</title>
|
|
153 <para>
|
|
154 The second kind of modifier is used to redirect the program's
|
|
155 "standard I/O paths" to alternate files or devices. Well-written
|
|
156 OS-9 programs use these paths for routine I/O. Because the programs
|
|
157 do not use specific file or device names, it is fairly simple to
|
|
158 "redirect" the I/O to any file or device without altering the
|
|
159 program itself. Programs which normally receive input from a
|
|
160 terminal or send output to a terminal use one or more of the
|
|
161 standard I/O paths as defined below:
|
|
162 </para>
|
|
163 <para>
|
|
164 STANDARD INPUT: This path normally passes data from the
|
|
165 terminal's keyboard to the program.
|
|
166 </para>
|
|
167 <para>
|
|
168 STANDARD OUTPUT PATH: This path is normally used to output
|
|
169 data from the program to the terminal's display.
|
|
170 </para>
|
|
171 <para>
|
|
172 STANDARD ERROR OUTPUT PATH: This path is used to output
|
|
173 routine status messages such as prompts and errors to the
|
|
174 terminal's display (defaults to the same device as the
|
|
175 standard output path). NOTE: The name "error output" is
|
|
176 sometimes misleading since many other kinds of messages besides
|
|
177 errors are sent on this path.
|
|
178 </para>
|
|
179 <para>
|
|
180 When new processes are created, they inherit their parent process'
|
|
181 standard I/O paths (See 5.3). Therefore, when the shell
|
|
182 creates new processes, they usually inherit its standard I/O paths.
|
|
183 When you log-on the shell's standard input is the terminal keyboard;
|
|
184 the standard output and error output is the terminal's display.
|
|
185 When a redirection modifier is used on a shell command line, the
|
|
186 shell will open the corresponding paths and pass them to the new
|
|
187 process as its standard I/O paths. There are three redirection
|
|
188 modifiers as given below:
|
|
189 </para>
|
|
190 <informaltable frame="none">
|
|
191 <tgroup cols="2">
|
|
192 <colspec colwidth="0.4in">
|
|
193 <colspec colwidth="3in">
|
|
194 <tbody>
|
|
195 <row>
|
|
196 <entry><</entry>
|
|
197 <entry>Redirect the standard input path</entry>
|
|
198 </row>
|
|
199 <row>
|
|
200 <entry>></entry>
|
|
201 <entry>Redirect the standard output path</entry>
|
|
202 </row>
|
|
203 <row>
|
|
204 <entry>>></entry>
|
|
205 <entry>Redirect the standard error output path</entry>
|
|
206 </row>
|
|
207 </tbody>
|
|
208 </tgroup>
|
|
209 </informaltable>
|
|
210
|
|
211 <para>
|
|
212 When redirection modifiers are used on a command line, they must
|
|
213 be immediately followed by a pathlist describing the file or device
|
|
214 the I/O is to be redirected to or from. For example, the standard
|
|
215 output of "list" can be redirected to write to the system printer
|
|
216 instead of the terminal:
|
|
217 </para>
|
|
218 <screen>
|
|
219 OS9: LIST correspondence >/p
|
|
220 </screen>
|
|
221 <para>
|
|
222 Files referenced by I/O redirection modifiers are automatically
|
|
223 opened or created, and closed (as appropriate) by the shell. Here is
|
|
224 another example, the output of the DIR command is redirected to the
|
|
225 file "/D1/savelisting":
|
|
226 </para>
|
|
227 <screen>
|
|
228 OS9: DIR >/D1/savelisting
|
|
229 </screen>
|
|
230 <para>
|
|
231 If the LIST command is used on the file "/D1/savelisting", output
|
|
232 from the DIR command will be displayed as shown below:
|
|
233 </para>
|
|
234 <screen>
|
|
235 OS9: LIST /D1/savelisting
|
|
236
|
|
237 Directory of . 10:15:00
|
|
238 myfile savelisting file1
|
|
239 </screen>
|
|
240 <para>
|
|
241 Redirection modifiers can be used before and/or after the program's
|
|
242 parameters, but each modifier can only be used once.
|
|
243 </para>
|
|
244 </section>
|
|
245 </section>
|
|
246
|
|
247 <section>
|
|
248 <title>Command Separators</title>
|
|
249 <para>
|
|
250 A single shell input line can request execution of more than one
|
|
251 program. These programs may be executed sequentially or
|
|
252 concurrently. Sequential execution means that one program must
|
|
253 complete its function and terminate before the next program is
|
|
254 allowed to begin execution. Concurrent execution means that several
|
|
255 programs are allowed to begin execution and run simultaneously.
|
|
256
|
|
257 </para>
|
|
258
|
|
259 <section>
|
|
260 <title>Sequential Execution</title>
|
|
261 <para>
|
|
262 Programs are executed sequentially when each is entered on a
|
|
263 separate line. More than one program can be specified on a single
|
|
264 shell command line by separating each
|
|
265 &replstart;program name&replend; &replstart;parameters&replend;
|
|
266 from the next one with a ";" character. For example:
|
|
267 </para>
|
|
268 <screen>
|
|
269 OS9: COPY myfile /D1/newfile ; DIR >/p
|
|
270 </screen>
|
|
271 <para>
|
|
272 This command line will first execute the COPY command and then the
|
|
273 DIR command.
|
|
274 </para>
|
|
275 <para>
|
|
276 If an error is returned by any program, subsequent commands on
|
|
277 the same line are not executed (regardless of the state of the "x"
|
|
278 option), otherwise, ";" and "return" are identical
|
|
279 separators.
|
|
280 </para>
|
|
281 <para>
|
|
282 Here are some more examples:
|
|
283 </para>
|
|
284 <screen>
|
|
285 OS9: copy oldfile newfile; del oldfile; list newfile
|
|
286
|
|
287 OS9: dir >/d1/myfile ; list temp >/p; del temp
|
|
288 </screen>
|
|
289 <para>
|
|
290 All programs executed sequentially are in fact separate, child
|
|
291 processes of the shell (See 5.3). After initiating execution of a
|
|
292 program to be executed sequentially, the shell enters the "wait"
|
|
293 state (See 5.2) until execution of the called program terminates.
|
|
294 </para>
|
|
295 </section>
|
|
296
|
|
297 <section>
|
|
298 <title>Concurrent Execution</title>
|
|
299 <para>
|
|
300 The second kind of separator is the "&" which implies concurrent
|
|
301 execution, meaning that the program is run (as a separate, child
|
|
302 process, see 5.3), but the shell does not wait for it to complete
|
|
303 before processing the next command.
|
|
304 </para>
|
|
305 <para>
|
|
306 The concurrent execution separator is therefore the means by
|
|
307 which multiprogramming (running two or more programs simultaneously)
|
|
308 is accomplished. The number of programs that can run at the same
|
|
309 time is not fixed: it depends upon the amount of free memory in the
|
|
310 system versus the memory requirements of the specific programs.
|
|
311 Here is an example:
|
|
312 </para>
|
|
313 <screen>
|
|
314 OS9: DIR >/P&
|
|
315 &007
|
|
316
|
|
317 OS9:
|
|
318 </screen>
|
|
319 <para>
|
|
320 This command line will cause shell to start the DIR command
|
|
321 executing, print the process ID number (&007), and then immediately
|
|
322 display the "OS9:" prompt and wait for another command to be
|
|
323 entered. Meanwhile the DIR command will be busy sending a directory
|
|
324 listing to the printer. You can display a "status summary" of all
|
|
325 processes you have created by using the PROCS command. Below is
|
|
326 another example:
|
|
327 </para>
|
|
328 <screen>
|
|
329 OS9: DIR >/P& LIST file1& COPY file1 file2 ; DEL temp
|
|
330 </screen>
|
|
331 <para>
|
|
332
|
|
333 </para>
|
|
334 <para>
|
|
335 Because they were followed by "&" separators, the DIR, LIST, and
|
|
336 COPY programs will run concurrently, but the DEL program will not
|
|
337 run until the COPY program has terminated because sequential
|
|
338 execution (";") was specified.
|
|
339 </para>
|
|
340 </section>
|
|
341
|
|
342 <section>
|
|
343 <title>Pipes and Filters</title>
|
|
344 <para>
|
|
345 The third kind of separator is the "!" character which is used to
|
|
346 construct "pipelines". Pipelines consist of two or more concurrent
|
|
347 programs whose standard input and/or output paths connect to each
|
|
348 other using "pipes".
|
|
349 </para>
|
|
350 <para>
|
|
351 Pipes are the primary means-by which data is transferred from
|
|
352 process to process (interprocess communications). Pipes are first-in,
|
|
353 first-out buffers that behave like mass-storage files.
|
|
354 </para>
|
|
355 <para>
|
|
356 I/O transfers using pipes are automatically buffered and
|
|
357 synchronized. A single pipe may have several "readers" and several
|
|
358 "writers". Multiple writers send, and multiple readers accept, data
|
|
359 to/from the pipe on a first-come, first-serve basis. An end-of-file
|
|
360 will occur if an attempt is made to read from a pipe but there are
|
|
361 no writers available to send data. Conversely, a write error will
|
|
362 occur if an attempt is made to write to a pipe having no readers.
|
|
363 </para>
|
|
364 <para>
|
|
365 Pipelines are created by the shell when an input line having one
|
|
366 or more "!" separators is processed. For each "!", the standard
|
|
367 output of the program named to the left of the "!" is redirected via
|
|
368 a pipe to the standard input of the program named to the right of
|
|
369 the "!". Individual pipes are created for each "!" present.
|
|
370 For example:
|
|
371 </para>
|
|
372 <screen>
|
|
373 OS9: update <master_file ! sort ! write_report >/p
|
|
374 </screen>
|
|
375 <para>
|
|
376 In the example above, the program "update" has its input redirected
|
|
377 from a path called "master_file". Its standard output becomes the
|
|
378 standard input for the program "sort". Its output, in turn, becomes
|
|
379 the standard input for the program "write_report", which has its
|
|
380 standard output redirected to the printer.
|
|
381 </para>
|
|
382 <para>
|
|
383 All programs in a pipeline are executed concurrently. The pipes
|
|
384 automatically synchronize the programs so the output of one never
|
|
385 "gets ahead" of the input request of the next program in the
|
|
386 pipeline. This implies that data cannot flow through a pipeline any
|
|
387 faster than the slowest program can process it. Some of the most
|
|
388 useful applications of pipelines are jobs like character set
|
|
389 conversion, print file formatting, data compression/decompression,
|
|
390 etc. Programs which are designed to process data as components of a
|
|
391 pipeline are often called "filters".
|
|
392 The "tee" command, which uses
|
|
393 pipes to allow data to be simultaneously "broadcast" from a single
|
|
394 input path to several output paths, is a useful filter.
|
|
395 </para>
|
|
396 </section>
|
|
397 </section>
|
|
398
|
|
399 <section>
|
|
400 <title>Command Grouping</title>
|
|
401 <para>
|
|
402 Sections of shell input lines can be enclosed in parentheses
|
|
403 which permits modifiers and separators to be applied to an entire
|
|
404 set of programs. The shell processes them by calling itself
|
|
405 recursively (as a new process) to execute the enclosed program list.
|
|
406 For example:
|
|
407 <screen>
|
|
408 OS9: (dir /d0; dir /d1) >/p
|
|
409 </screen>
|
|
410 gives the same result as:
|
|
411 <screen>
|
|
412 OS9: dir /d0 >/p; dir /d1 >/p
|
|
413 </screen>
|
|
414 except for the subtle difference that the printer is "kept"
|
|
415 continuously in the first example; in the second case another user
|
|
416 could "steal" the printer in between the "dir" commands.
|
|
417 </para>
|
|
418 <para>
|
|
419 Command grouping can be used to cause a group of programs to be
|
|
420 executed sequentially, but also concurrently with respect to the
|
|
421 shell that initiated them, such as:
|
|
422 </para>
|
|
423 <screen>
|
|
424 OS9: (del file1; del file2; del file3)&
|
|
425 </screen>
|
|
426 <para>
|
|
427 A useful extension of this form is to construct pipelines consisting
|
|
428 of sequential and/or concurrent programs. For example:
|
|
429 </para>
|
|
430 <screen>
|
|
431 OS9: (dir CMDS; dir SYS) ! makeuppercase ! transmit
|
|
432 </screen>
|
|
433 <para>
|
|
434 Here is a very practical example of the use of pipelines. Recall
|
|
435 that the "DSAVE" command generates a procedure file to copy all the
|
|
436 files in a directory. The example below shows how the output of
|
|
437 "DSAVE" can be pipelined to a shell which will execute the OS-9
|
|
438 commands as they are generated by DSAVE. Assume that we want to
|
|
439 copy all files from a directory called WORKING to a directory called
|
|
440 ARCHIVE:
|
|
441 </para>
|
|
442 <screen>
|
|
443 OS9: chd /d0/WORKING; dsave ! (chd /d0/ARCHIVE)
|
|
444 </screen>
|
|
445 </section>
|
|
446
|
|
447 <section>
|
|
448 <title>Built-in Shell Commands and Options</title>
|
|
449 <para>
|
|
450 When processing input lines, the shell looks for several special
|
|
451 names of commands or option switches that are built-in the shell.
|
|
452 These commands are executed without loading a program and creating a
|
|
453 new process, and generally affect how the shell operates. They can
|
|
454 be used at the beginning of a line, or following any program
|
|
455 separator (";", "&", or "!").
|
|
456 Two or more adjacent built-in
|
|
457 commands can be separated by spaces or commas.
|
|
458 </para>
|
|
459 <para>
|
|
460 The built-in commands and their functions are:
|
|
461 </para>
|
|
462 <informaltable frame="none">
|
|
463 <tgroup cols="2">
|
|
464 <colspec colwidth="1.5in">
|
|
465 <colspec colwidth="3.5in">
|
|
466 <tbody>
|
|
467 <row>
|
|
468 <entry>chd &replstart;pathlist&replend;</entry>
|
|
469 <entry>change the working data directory to the directory
|
|
470 specified by the pathlist (see 3.6).</entry>
|
|
471 </row>
|
|
472 <row>
|
|
473 <entry>chx &replstart;pathlist&replend;</entry>
|
|
474 <entry>change the working execution directory to the
|
|
475 directory specified by the pathlist (see 3.6).</entry>
|
|
476 </row>
|
|
477 <row>
|
|
478 <entry>ex name</entry>
|
|
479 <entry>directly execute the module named. This
|
|
480 transforms the shell process so it ceases
|
|
481 to exist and a new module begins execution in
|
|
482 its place.</entry>
|
|
483 </row>
|
|
484 <row>
|
|
485 <entry>w</entry>
|
|
486 <entry>wait for any process to terminate.</entry>
|
|
487 </row>
|
|
488 <row>
|
|
489 <entry>* text</entry>
|
|
490 <entry>comment: "text" is not processed.</entry>
|
|
491 </row>
|
|
492 <row>
|
|
493 <entry>kill &replstart;Proc ID&replend;</entry>
|
|
494 <entry>abort the process specified.</entry>
|
|
495 </row>
|
|
496 <row>
|
|
497 <entry>setpr &replstart;proc ID&replend; &replstart;priority&replend;</entry>
|
|
498 <entry>changes process' priority (see 5.1).</entry>
|
|
499 </row>
|
|
500 <row>
|
|
501 <entry>x</entry>
|
|
502 <entry>causes shell to abort on any error (default)</entry>
|
|
503 </row>
|
|
504 <row>
|
|
505 <entry>-x</entry>
|
|
506 <entry>causes shell not to abort on error (See 4.7)</entry>
|
|
507 </row>
|
|
508 <row>
|
|
509 <entry>p</entry>
|
|
510 <entry>turns shell prompt and messages on (default)</entry>
|
|
511 </row>
|
|
512 <row>
|
|
513 <entry>-p</entry>
|
|
514 <entry>inhibits shell prompt and messages</entry>
|
|
515 </row>
|
|
516 <row>
|
|
517 <entry>t</entry>
|
|
518 <entry>makes shell copy all input lines to output</entry>
|
|
519 </row>
|
|
520 <row>
|
|
521 <entry>-t</entry>
|
|
522 <entry>does not copy input lines to output (default)</entry>
|
|
523 </row>
|
|
524 </tbody>
|
|
525 </tgroup>
|
|
526 </informaltable>
|
|
527
|
|
528
|
|
529 <para>
|
|
530 The change directory commands switch the shell's working directory
|
|
531 and, by inheritance, any subsequently created child process. The
|
|
532 "ex" command is used where the shell is needed to initiate execution
|
|
533 of a program without the overhead of a suspended "shell" process.
|
|
534 The name used is processed according to standard shell operation,
|
|
535 and modifiers can be used.
|
|
536 </para>
|
|
537 </section>
|
|
538
|
|
539 <section>
|
|
540 <title>Shell Procedure Files</title>
|
|
541 <para>
|
|
542 The shell is a reentrant program that can be simultaneously
|
|
543 executed by more than one process at a time. As is the case with
|
|
544 most other OS-9 programs, it uses standard I/O paths for routine
|
|
545 input and output (see 4.2.3). specifically, it requests command
|
|
546 lines from the standard input path and writes its prompts and other
|
|
547 data to the standard error path.
|
|
548 </para>
|
|
549 <para>
|
|
550 The shell can start up another process also running the shell by
|
|
551 means of the "shell" command. If the standard input path is
|
|
552 redirected to a mass storage file, the new "incarnation" of the
|
|
553 shell can accept and execute command lines from the file instead of
|
|
554 a terminal keyboard. The text file (see 3.9.2) to be processed is
|
|
555 called a "procedure file". It contains one or more command lines
|
|
556 that are identical to command lines that are manually entered from
|
|
557 the keyboard. This technique is sometimes called "batch" or
|
|
558 "background" processing.
|
|
559 </para>
|
|
560 <para>
|
|
561 If the &replstart;program name&replend; specified on a shell command line can not be
|
|
562 found in memory or in the execution directory, shell will search the
|
|
563 data directory for a file with the desired name. If one is found,
|
|
564 shell will automatically execute it as a procedure file (see 2.0).
|
|
565 </para>
|
|
566 <para>
|
|
567 Execution of procedure files have a number of valuable
|
|
568 applications. It can eliminate repetitive manual entry of commonly-used
|
|
569 sequences of commands. It can allow the computer to execute a
|
|
570 lengthy series of programs "in the background" while the computer is
|
|
571 unattended or while the user is running other programs "in the
|
|
572 foreground".
|
|
573 </para>
|
|
574 <para>
|
|
575 In addition to redirecting the shell's standard input to a
|
|
576 procedure file, the standard output and standard error output can be
|
|
577 redirected to another file which can record output for later review
|
|
578 or printing. This can also eliminate the sometimes-annoying output
|
|
579 of shell messages to your terminal at random times.
|
|
580 </para>
|
|
581 <para>
|
|
582 Here are two simple ways to use the shell to create another
|
|
583 shell:
|
|
584 </para>
|
|
585 <screen>
|
|
586 OS9: shell <procfile
|
|
587
|
|
588 OS9: procfile
|
|
589 </screen>
|
|
590 <para>
|
|
591 Both do exactly the same thing: execute the commands of the file
|
|
592 "procfile". To run the procedure file in a "background" mode you
|
|
593 simply add the ampersand operator:
|
|
594 </para>
|
|
595 <screen>
|
|
596 OS9: procfile&
|
|
597 </screen>
|
|
598 <para>
|
|
599 OS-9 does not have any constraints on the number of jobs that can be
|
|
600 simultaneously executed as long as there is memory available (see
|
|
601 5.4). Also, the procedure files can themselves cause sequential or
|
|
602 concurrent execution of additional procedure files. Here's a more
|
|
603 complex example of initiating two processing streams with
|
|
604 redirection of each shell's output to files:
|
|
605 </para>
|
|
606 <screen>
|
|
607 OS9: proc1 T >>stat1& proc2 T >>stat2&
|
|
608 </screen>
|
|
609 <para>
|
|
610 Note that the built-in command "T" (copy input lines to error
|
|
611 output) was used above. They make the output file contain a record
|
|
612 of all lines executed, but without useless "OS9" prompts intermixed.
|
|
613 The "-x" built-in command can be used if you do
|
|
614 <emphasis>not</emphasis> want processing
|
|
615 to stop if an error occurs. Note that the built-in commands only
|
|
616 affect the shell that executes them, and not any others that may
|
|
617 exist.
|
|
618 </para>
|
|
619 </section>
|
|
620
|
|
621 <section>
|
|
622 <title>Error Reporting</title>
|
|
623 <para>
|
|
624 Many programs (including the shell) use OS-9's standard error
|
|
625 reporting function, which displays an error number on the error
|
|
626 output path. The standard error codes are listed in the Appendix of
|
|
627 this manual. If desired, the "printerr" command can be executed,
|
|
628 which replaces the smaller, built-in error display routine with a
|
|
629 larger (and slower) routine that looks up descriptive error messages
|
|
630 from a text file called "/d0/sys/errmsg".
|
|
631 Once the "printerr"
|
|
632 command has been run it cannot be turned off. Also, its effect is
|
|
633 system-wide.
|
|
634 </para>
|
|
635 <para>
|
|
636 Programs called by the shell can return an error code in the MPU
|
|
637 "B" register (otherwise B should be cleared) upon termination. This
|
|
638 type of error, as well as errors detected by the shell itself, will
|
|
639 cause an error message to be displayed and processing of the command
|
|
640 line or procedure file to be terminated unless the "-x" built-in
|
|
641 command has been previously executed (See 4.5).
|
|
642 </para>
|
|
643 </section>
|
|
644
|
|
645 <section>
|
|
646 <title>Running Compiled Intermediate Code Programs</title>
|
|
647 <para>
|
|
648 Before the shell executes a program, it checks the program
|
|
649 module's language type. If its type is not 6809 machine language,
|
|
650 shell will call the appropriate run-time system for that module.
|
|
651 Versions of the shell supplied for various systems are capable of
|
|
652 calling different run-time systems. Most versions of shell call
|
|
653 Basic09 when appropriate, and Level Two versions of shell can also
|
|
654 call the Pascal P-code interpreter (PascalN), or the CIS Cobol
|
|
655 runtime system (RunC).
|
|
656 </para>
|
|
657 <para>
|
|
658 For example, if you wanted to run a BASIC09 I-code module called
|
|
659 "adventure", you could type the command given below:
|
|
660 </para>
|
|
661 <screen>
|
|
662 OS9: BASIC09 adventure
|
|
663 </screen>
|
|
664 <para>
|
|
665 Or you could accomplish the same thing by typing the following:
|
|
666 </para>
|
|
667 <screen>
|
|
668 OS9: adventure
|
|
669 </screen>
|
|
670 </section>
|
|
671
|
|
672 <section>
|
|
673 <title>Setting Up Timesharing System Procedure Files</title>
|
|
674
|
|
675 <para>
|
|
676 OS-9 systems used for timesharing usually have a procedure file
|
|
677 that brings the system up by means of one simple command or by using
|
|
678 the system "startup" file. A procedure file which initiates the
|
|
679 timesharing monitor for each terminal is executed to start up the
|
|
680 system. The procedure file first starts the system clock, then
|
|
681 initiates concurrent execution of a number of processes that have
|
|
682 their I/O redirected to each timesharing terminal.
|
|
683 </para>
|
|
684 <para>
|
|
685 Usually one TSMON command program is started up concurrently for
|
|
686 each terminal in the system. This is a special program which
|
|
687 monitors a terminal for activity. When a carriage return character
|
|
688 is typed on any of these terminals, the TSMON command initiates the
|
|
689 LOGIN command program. If a user does not enter a correct password
|
|
690 or user number in three tries, the LOGIN command will be aborted.
|
|
691 Here's a sample procedure file for a 4-terminal timesharing system
|
|
692 having terminals names "TERM", "T1",
|
|
693 "T2", and "T3".
|
|
694 </para>
|
|
695 <programlisting>
|
|
696 * system startup procedure file
|
|
697 echo Please Enter the Date and Time
|
|
698 setime </term
|
|
699 printerr
|
|
700 tsmon /t1&
|
|
701 tsmon /t2&
|
|
702 tsmon /t3&
|
|
703 </programlisting>
|
|
704 <para>
|
|
705 NOTE: This LOGIN procedure will not work until a password file
|
|
706 called "/D0/SYS/PASSWORD" has been created. For more information,
|
|
707 please see the LOGIN command description.
|
|
708 </para>
|
|
709 <para>
|
|
710 The example above deserves special attention. Note that the
|
|
711 "setime" command has its input redirected to the system console
|
|
712 "term", which is necessary because it would otherwise attempt to
|
|
713 read the time information from its current standard input path,
|
|
714 which is the procedure file and not the keyboard.
|
|
715 </para>
|
|
716 </section>
|
|
717 </chapter>
|