Mercurial > hg > Members > kono > nitros9-code
annotate docs/nitros9guide/chap4.chapter @ 3295:6b7a7b233925 default tip
makefile: Allow PORTS with level1/2 mix
https://sourceforge.net/p/nitros9/feature-requests/10/
author | Tormod Volden <debian.tormod@gmail.com> |
---|---|
date | Tue, 19 Apr 2022 18:12:17 +0200 |
parents | b00cf13c9f61 |
children |
rev | line source |
---|---|
144 | 1 <chapter> |
2 <title>Advanced Features of the Shell</title> | |
3 <para> | |
1011 | 4 The basic shell functions were introduced in a prior chapter in order |
1500 | 5 to provide an understanding of how basic NitrOS-9 commands work. In |
144 | 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"> | |
646 | 85 <colspec colwidth="2in"/> |
86 <colspec colwidth="3in"/> | |
144 | 87 <tbody> |
88 <row> | |
89 <entry>asm</entry> | |
90 <entry>is the verb</entry> | |
91 </row> | |
92 <row> | |
93 <entry>sourcefile l -o</entry> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
94 <entry>are parameters passed to <command>asm</command></entry> |
144 | 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 | |
1011 | 115 assumes it is a program name and attempts to locate and execute it. |
144 | 116 </para> |
117 </section> | |
118 | |
119 <section> | |
120 <title>Execution Modifiers</title> | |
121 <para> | |
122 Execution modifiers are processed by the shell before the program | |
123 is run. If an error is detected in any of the modifiers, the run | |
124 will be aborted and the error reported. Characters which comprise | |
125 modifiers are stripped from the part(s) of the command line passed | |
126 to the program as parameters, therefore, the characters reserved for | |
127 use as modifiers ( # ; ! < > & ) cannot be used inside parameters, | |
128 but can be used before or after the parameters. | |
129 </para> | |
130 | |
131 <section> | |
132 <title>Alternate Memory Size Modifier</title> | |
133 <para> | |
134 When command programs are invoked by the shell, they are | |
135 allocated the minimum amount of working RAM memory specified in the | |
136 program's module header. A module header is part of all executable | |
137 programs and holds the program's name, size, memory requirements, | |
1011 | 138 etc. Sometimes it is desirable to increase this default |
144 | 139 memory size. Memory can be assigned in 256-byte pages using the |
140 modifier "#n" where n is the decimal number of pages, or in 1024 | |
141 byte increments using the modifier "#nK". The two examples below | |
142 behave identically: | |
143 </para> | |
144 <screen> | |
145 OS9: copy #8 file1 file2 (gives 8*256 = 2048 bytes) | |
146 OS9: copy #2K file1 file2 (gives 2*1024 = 2048 bytes) | |
147 </screen> | |
148 </section> | |
149 | |
150 <section> | |
151 <title>I/O Redirection Modifiers</title> | |
152 <para> | |
153 The second kind of modifier is used to redirect the program's | |
154 "standard I/O paths" to alternate files or devices. Well-written | |
1500 | 155 NitrOS-9 programs use these paths for routine I/O. Because the programs |
144 | 156 do not use specific file or device names, it is fairly simple to |
157 "redirect" the I/O to any file or device without altering the | |
158 program itself. Programs which normally receive input from a | |
159 terminal or send output to a terminal use one or more of the | |
160 standard I/O paths as defined below: | |
161 </para> | |
162 <para> | |
163 STANDARD INPUT: This path normally passes data from the | |
164 terminal's keyboard to the program. | |
165 </para> | |
166 <para> | |
167 STANDARD OUTPUT PATH: This path is normally used to output | |
168 data from the program to the terminal's display. | |
169 </para> | |
170 <para> | |
171 STANDARD ERROR OUTPUT PATH: This path is used to output | |
172 routine status messages such as prompts and errors to the | |
173 terminal's display (defaults to the same device as the | |
174 standard output path). NOTE: The name "error output" is | |
175 sometimes misleading since many other kinds of messages besides | |
176 errors are sent on this path. | |
177 </para> | |
178 <para> | |
179 When new processes are created, they inherit their parent process' | |
1011 | 180 standard I/O paths. Therefore, when the shell |
144 | 181 creates new processes, they usually inherit its standard I/O paths. |
182 When you log-on the shell's standard input is the terminal keyboard; | |
183 the standard output and error output is the terminal's display. | |
184 When a redirection modifier is used on a shell command line, the | |
185 shell will open the corresponding paths and pass them to the new | |
186 process as its standard I/O paths. There are three redirection | |
187 modifiers as given below: | |
188 </para> | |
189 <informaltable frame="none"> | |
190 <tgroup cols="2"> | |
646 | 191 <colspec colwidth="0.4in"/> |
192 <colspec colwidth="3in"/> | |
144 | 193 <tbody> |
194 <row> | |
195 <entry><</entry> | |
196 <entry>Redirect the standard input path</entry> | |
197 </row> | |
198 <row> | |
199 <entry>></entry> | |
200 <entry>Redirect the standard output path</entry> | |
201 </row> | |
202 <row> | |
203 <entry>>></entry> | |
204 <entry>Redirect the standard error output path</entry> | |
205 </row> | |
206 </tbody> | |
207 </tgroup> | |
208 </informaltable> | |
209 | |
210 <para> | |
211 When redirection modifiers are used on a command line, they must | |
212 be immediately followed by a pathlist describing the file or device | |
213 the I/O is to be redirected to or from. For example, the standard | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
214 output of <command>list</command> can be redirected to write to the system printer |
144 | 215 instead of the terminal: |
216 </para> | |
217 <screen> | |
1011 | 218 OS9: list correspondence >/p |
144 | 219 </screen> |
220 <para> | |
221 Files referenced by I/O redirection modifiers are automatically | |
222 opened or created, and closed (as appropriate) by the shell. Here is | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
223 another example, the output of the <command>dir</command> command is redirected to the |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
224 file <filename>/D1/savelisting</filename>: |
144 | 225 </para> |
226 <screen> | |
227 OS9: DIR >/D1/savelisting | |
228 </screen> | |
229 <para> | |
1094 | 230 If the <command>list</command> command is used on the file <filename>/D1/savelisting</filename>, output |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
231 from the <command>dir</command> command will be displayed as shown below: |
144 | 232 </para> |
233 <screen> | |
1011 | 234 OS9: list /d1/savelisting |
144 | 235 |
236 Directory of . 10:15:00 | |
237 myfile savelisting file1 | |
238 </screen> | |
239 <para> | |
240 Redirection modifiers can be used before and/or after the program's | |
241 parameters, but each modifier can only be used once. | |
242 </para> | |
243 </section> | |
244 </section> | |
245 | |
1093 | 246 <section id="sec4.3"> |
144 | 247 <title>Command Separators</title> |
248 <para> | |
249 A single shell input line can request execution of more than one | |
250 program. These programs may be executed sequentially or | |
251 concurrently. Sequential execution means that one program must | |
252 complete its function and terminate before the next program is | |
253 allowed to begin execution. Concurrent execution means that several | |
254 programs are allowed to begin execution and run simultaneously. | |
255 | |
256 </para> | |
257 | |
1093 | 258 <section id="sec4.3.1"> |
144 | 259 <title>Sequential Execution</title> |
260 <para> | |
261 Programs are executed sequentially when each is entered on a | |
262 separate line. More than one program can be specified on a single | |
263 shell command line by separating each | |
975
c565a4700689
The entitity replstart was replaced with <replaceable>
roug
parents:
646
diff
changeset
|
264 <replaceable>program name</replaceable> <replaceable>parameters</replaceable> |
144 | 265 from the next one with a ";" character. For example: |
266 </para> | |
267 <screen> | |
1011 | 268 OS9: copy myfile /d1/newfile ; dir >/p |
144 | 269 </screen> |
270 <para> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
271 This command line will first execute the <command>copy</command> command and then the |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
272 <command>dir</command> command. |
144 | 273 </para> |
274 <para> | |
275 If an error is returned by any program, subsequent commands on | |
276 the same line are not executed (regardless of the state of the "x" | |
277 option), otherwise, ";" and "return" are identical | |
278 separators. | |
279 </para> | |
280 <para> | |
281 Here are some more examples: | |
282 </para> | |
283 <screen> | |
284 OS9: copy oldfile newfile; del oldfile; list newfile | |
285 | |
286 OS9: dir >/d1/myfile ; list temp >/p; del temp | |
287 </screen> | |
288 <para> | |
289 All programs executed sequentially are in fact separate, child | |
1011 | 290 processes of the shell. After initiating execution of a |
144 | 291 program to be executed sequentially, the shell enters the "wait" |
1011 | 292 state until execution of the called program terminates. |
144 | 293 </para> |
294 </section> | |
295 | |
1093 | 296 <section id="sec4.3.2"> |
144 | 297 <title>Concurrent Execution</title> |
298 <para> | |
299 The second kind of separator is the "&" which implies concurrent | |
300 execution, meaning that the program is run (as a separate, child | |
1011 | 301 process), but the shell does not wait for it to complete |
144 | 302 before processing the next command. |
303 </para> | |
304 <para> | |
305 The concurrent execution separator is therefore the means by | |
306 which multiprogramming (running two or more programs simultaneously) | |
307 is accomplished. The number of programs that can run at the same | |
308 time is not fixed: it depends upon the amount of free memory in the | |
309 system versus the memory requirements of the specific programs. | |
310 Here is an example: | |
311 </para> | |
312 <screen> | |
1011 | 313 OS9: dir >/p& |
144 | 314 &007 |
315 | |
316 OS9: | |
317 </screen> | |
318 <para> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
319 This command line will cause shell to start the <command>dir</command> command |
144 | 320 executing, print the process ID number (&007), and then immediately |
321 display the "OS9:" prompt and wait for another command to be | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
322 entered. Meanwhile the <command>dir</command> command will be busy sending a directory |
144 | 323 listing to the printer. You can display a "status summary" of all |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
324 processes you have created by using the <command>procs</command> command. Below is |
144 | 325 another example: |
326 </para> | |
327 <screen> | |
1011 | 328 OS9: dir >/p& list file1& copy file1 file2 ; del temp |
144 | 329 </screen> |
330 <para> | |
331 | |
332 </para> | |
333 <para> | |
1094 | 334 Because they were followed by "&" separators, the <command>dir</command>, |
335 <command>list</command>, and | |
336 <command>copy</command> programs will run concurrently, | |
337 but the <command>del</command> program will not | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
338 run until the <command>copy</command> program has terminated because sequential |
144 | 339 execution (";") was specified. |
340 </para> | |
341 </section> | |
342 | |
1093 | 343 <section id="sec4.3.3"> |
144 | 344 <title>Pipes and Filters</title> |
345 <para> | |
346 The third kind of separator is the "!" character which is used to | |
347 construct "pipelines". Pipelines consist of two or more concurrent | |
348 programs whose standard input and/or output paths connect to each | |
349 other using "pipes". | |
350 </para> | |
351 <para> | |
352 Pipes are the primary means-by which data is transferred from | |
353 process to process (interprocess communications). Pipes are first-in, | |
354 first-out buffers that behave like mass-storage files. | |
355 </para> | |
356 <para> | |
357 I/O transfers using pipes are automatically buffered and | |
358 synchronized. A single pipe may have several "readers" and several | |
359 "writers". Multiple writers send, and multiple readers accept, data | |
360 to/from the pipe on a first-come, first-serve basis. An end-of-file | |
361 will occur if an attempt is made to read from a pipe but there are | |
362 no writers available to send data. Conversely, a write error will | |
363 occur if an attempt is made to write to a pipe having no readers. | |
364 </para> | |
365 <para> | |
366 Pipelines are created by the shell when an input line having one | |
367 or more "!" separators is processed. For each "!", the standard | |
368 output of the program named to the left of the "!" is redirected via | |
369 a pipe to the standard input of the program named to the right of | |
370 the "!". Individual pipes are created for each "!" present. | |
371 For example: | |
372 </para> | |
373 <screen> | |
374 OS9: update <master_file ! sort ! write_report >/p | |
375 </screen> | |
376 <para> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
377 In the example above, the program <command>update</command> has its input redirected |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
378 from a path called <filename>master_file</filename>. Its standard output becomes the |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
379 standard input for the program <command>sort</command>. Its output, in turn, becomes |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
380 the standard input for the program <command>write_report</command>, which has its |
144 | 381 standard output redirected to the printer. |
382 </para> | |
383 <para> | |
384 All programs in a pipeline are executed concurrently. The pipes | |
385 automatically synchronize the programs so the output of one never | |
386 "gets ahead" of the input request of the next program in the | |
387 pipeline. This implies that data cannot flow through a pipeline any | |
388 faster than the slowest program can process it. Some of the most | |
389 useful applications of pipelines are jobs like character set | |
390 conversion, print file formatting, data compression/decompression, | |
391 etc. Programs which are designed to process data as components of a | |
392 pipeline are often called "filters". | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
393 The <command>tee</command> command, which uses |
144 | 394 pipes to allow data to be simultaneously "broadcast" from a single |
395 input path to several output paths, is a useful filter. | |
396 </para> | |
397 </section> | |
398 </section> | |
399 | |
400 <section> | |
401 <title>Command Grouping</title> | |
402 <para> | |
403 Sections of shell input lines can be enclosed in parentheses | |
404 which permits modifiers and separators to be applied to an entire | |
405 set of programs. The shell processes them by calling itself | |
406 recursively (as a new process) to execute the enclosed program list. | |
407 For example: | |
408 <screen> | |
409 OS9: (dir /d0; dir /d1) >/p | |
410 </screen> | |
411 gives the same result as: | |
412 <screen> | |
413 OS9: dir /d0 >/p; dir /d1 >/p | |
414 </screen> | |
415 except for the subtle difference that the printer is "kept" | |
416 continuously in the first example; in the second case another user | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
417 could "steal" the printer in between the <command>dir</command> commands. |
144 | 418 </para> |
419 <para> | |
420 Command grouping can be used to cause a group of programs to be | |
421 executed sequentially, but also concurrently with respect to the | |
422 shell that initiated them, such as: | |
423 </para> | |
424 <screen> | |
425 OS9: (del file1; del file2; del file3)& | |
426 </screen> | |
427 <para> | |
428 A useful extension of this form is to construct pipelines consisting | |
429 of sequential and/or concurrent programs. For example: | |
430 </para> | |
431 <screen> | |
432 OS9: (dir CMDS; dir SYS) ! makeuppercase ! transmit | |
433 </screen> | |
434 <para> | |
435 Here is a very practical example of the use of pipelines. Recall | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
436 that the <command>dsave</command> command generates a procedure file to copy all the |
144 | 437 files in a directory. The example below shows how the output of |
1500 | 438 <command>dsave</command> can be pipelined to a shell which will execute the NitrOS-9 |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
439 commands as they are generated by <command>dsave</command>. Assume that we want to |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
440 copy all files from a directory called <filename class="directory">WORKING</filename> to a directory called |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
441 <filename class="directory">ARCHIVE</filename>: |
144 | 442 </para> |
443 <screen> | |
1011 | 444 OS9: chd /d0/WORKING; dsave /d0/ARCHIVE ! shell -p |
144 | 445 </screen> |
446 </section> | |
447 | |
1093 | 448 <section id="sec4.5"> |
144 | 449 <title>Built-in Shell Commands and Options</title> |
450 <para> | |
451 When processing input lines, the shell looks for several special | |
452 names of commands or option switches that are built-in the shell. | |
453 These commands are executed without loading a program and creating a | |
454 new process, and generally affect how the shell operates. They can | |
455 be used at the beginning of a line, or following any program | |
456 separator (";", "&", or "!"). | |
457 Two or more adjacent built-in | |
458 commands can be separated by spaces or commas. | |
459 </para> | |
460 <para> | |
461 The built-in commands and their functions are: | |
462 </para> | |
463 <informaltable frame="none"> | |
464 <tgroup cols="2"> | |
646 | 465 <colspec colwidth="1.5in"/> |
466 <colspec colwidth="3.5in"/> | |
144 | 467 <tbody> |
468 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
469 <entry><command>chd</command> <replaceable>pathlist</replaceable></entry> |
144 | 470 <entry>change the working data directory to the directory |
1011 | 471 specified by the pathlist.</entry> |
144 | 472 </row> |
473 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
474 <entry><command>chx</command> <replaceable>pathlist</replaceable></entry> |
144 | 475 <entry>change the working execution directory to the |
1011 | 476 directory specified by the pathlist.</entry> |
144 | 477 </row> |
478 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
479 <entry><command>ex</command> <replaceable>name</replaceable></entry> |
144 | 480 <entry>directly execute the module named. This |
481 transforms the shell process so it ceases | |
482 to exist and a new module begins execution in | |
483 its place.</entry> | |
484 </row> | |
485 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
486 <entry><command>w</command></entry> |
144 | 487 <entry>wait for any process to terminate.</entry> |
488 </row> | |
489 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
490 <entry>* <replaceable>text</replaceable></entry> |
144 | 491 <entry>comment: "text" is not processed.</entry> |
492 </row> | |
493 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
494 <entry><command>kill</command> <replaceable>Proc ID</replaceable></entry> |
144 | 495 <entry>abort the process specified.</entry> |
496 </row> | |
497 <row> | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
498 <entry><command>setpr</command> <replaceable>Proc ID</replaceable> <replaceable>priority</replaceable></entry> |
1011 | 499 <entry>changes process' priority.</entry> |
144 | 500 </row> |
501 <row> | |
502 <entry>x</entry> | |
503 <entry>causes shell to abort on any error (default)</entry> | |
504 </row> | |
505 <row> | |
506 <entry>-x</entry> | |
1011 | 507 <entry>causes shell not to abort on error</entry> |
144 | 508 </row> |
509 <row> | |
510 <entry>p</entry> | |
511 <entry>turns shell prompt and messages on (default)</entry> | |
512 </row> | |
513 <row> | |
514 <entry>-p</entry> | |
515 <entry>inhibits shell prompt and messages</entry> | |
516 </row> | |
517 <row> | |
518 <entry>t</entry> | |
519 <entry>makes shell copy all input lines to output</entry> | |
520 </row> | |
521 <row> | |
522 <entry>-t</entry> | |
523 <entry>does not copy input lines to output (default)</entry> | |
524 </row> | |
525 </tbody> | |
526 </tgroup> | |
527 </informaltable> | |
528 | |
529 | |
530 <para> | |
531 The change directory commands switch the shell's working directory | |
532 and, by inheritance, any subsequently created child process. The | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
533 <command>ex</command> command is used where the shell is needed to initiate execution |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
534 of a program without the overhead of a suspended <command>shell</command> process. |
144 | 535 The name used is processed according to standard shell operation, |
536 and modifiers can be used. | |
537 </para> | |
538 </section> | |
539 | |
1093 | 540 <section id="sec4.6"> |
144 | 541 <title>Shell Procedure Files</title> |
542 <para> | |
543 The shell is a reentrant program that can be simultaneously | |
544 executed by more than one process at a time. As is the case with | |
1500 | 545 most other NitrOS-9 programs, it uses standard I/O paths for routine |
1011 | 546 input and output. specifically, it requests command |
144 | 547 lines from the standard input path and writes its prompts and other |
548 data to the standard error path. | |
549 </para> | |
550 <para> | |
551 The shell can start up another process also running the shell by | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
552 means of the <command>shell</command> command. If the standard input path is |
144 | 553 redirected to a mass storage file, the new "incarnation" of the |
554 shell can accept and execute command lines from the file instead of | |
1011 | 555 a terminal keyboard. The text file to be processed is |
144 | 556 called a "procedure file". It contains one or more command lines |
557 that are identical to command lines that are manually entered from | |
558 the keyboard. This technique is sometimes called "batch" or | |
559 "background" processing. | |
560 </para> | |
561 <para> | |
975
c565a4700689
The entitity replstart was replaced with <replaceable>
roug
parents:
646
diff
changeset
|
562 If the <replaceable>program name</replaceable> specified on a shell command line can not be |
144 | 563 found in memory or in the execution directory, shell will search the |
564 data directory for a file with the desired name. If one is found, | |
1011 | 565 shell will automatically execute it as a procedure file. |
144 | 566 </para> |
567 <para> | |
568 Execution of procedure files have a number of valuable | |
569 applications. It can eliminate repetitive manual entry of commonly-used | |
570 sequences of commands. It can allow the computer to execute a | |
571 lengthy series of programs "in the background" while the computer is | |
572 unattended or while the user is running other programs "in the | |
573 foreground". | |
574 </para> | |
575 <para> | |
576 In addition to redirecting the shell's standard input to a | |
577 procedure file, the standard output and standard error output can be | |
578 redirected to another file which can record output for later review | |
579 or printing. This can also eliminate the sometimes-annoying output | |
580 of shell messages to your terminal at random times. | |
581 </para> | |
582 <para> | |
583 Here are two simple ways to use the shell to create another | |
584 shell: | |
585 </para> | |
586 <screen> | |
587 OS9: shell <procfile | |
588 | |
589 OS9: procfile | |
590 </screen> | |
591 <para> | |
592 Both do exactly the same thing: execute the commands of the file | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
593 <filename>procfile</filename>. To run the procedure file in a "background" mode you |
144 | 594 simply add the ampersand operator: |
595 </para> | |
596 <screen> | |
597 OS9: procfile& | |
598 </screen> | |
599 <para> | |
1500 | 600 NitrOS-9 does not have any constraints on the number of jobs that can be |
1011 | 601 simultaneously executed as long as there is memory available. Also, the procedure files can themselves cause sequential or |
144 | 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 | |
1093 | 621 <section id="sec4.7"> |
144 | 622 <title>Error Reporting</title> |
623 <para> | |
1500 | 624 Many programs (including the shell) use NitrOS-9's standard error |
144 | 625 reporting function, which displays an error number on the error |
1094 | 626 output path. The standard error codes are listed in the <xref linkend="errorcodes"/> of |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
627 this manual. If desired, the <command>printerr</command> command can be executed, |
144 | 628 which replaces the smaller, built-in error display routine with a |
629 larger (and slower) routine that looks up descriptive error messages | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
630 from a text file called <filename>/dd/sys/errmsg</filename>. |
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
631 Once the <command>printerr</command> |
144 | 632 command has been run it cannot be turned off. Also, its effect is |
633 system-wide. | |
634 </para> | |
635 <para> | |
1011 | 636 Programs called by the shell can return an error code in the CPU's |
144 | 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 | |
1011 | 641 command has been previously executed. |
144 | 642 </para> |
643 </section> | |
644 | |
1093 | 645 <section id="sec4.8"> |
144 | 646 <title>Running Compiled Intermediate Code Programs</title> |
647 <para> | |
648 Before the shell executes a program, it checks the program | |
1014
d9ed9d44b70c
Some character entities had missing semicolons. It's &CPU;
roug
parents:
1011
diff
changeset
|
649 module's language type. If its type is not &CPU; machine language, |
144 | 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> | |
1011 | 658 For example, if you wanted to run a Basic09 I-code module called |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
659 <command>adventure</command>, you could type the command given below: |
144 | 660 </para> |
661 <screen> | |
1011 | 662 OS9: basic09 adventure |
144 | 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 | |
1093 | 672 <section id="sec4.9"> |
144 | 673 <title>Setting Up Timesharing System Procedure Files</title> |
674 | |
675 <para> | |
1500 | 676 NitrOS-9 systems used for timesharing usually have a procedure file |
144 | 677 that brings the system up by means of one simple command or by using |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
678 the system <filename>startup</filename> file. A procedure file which initiates the |
144 | 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> | |
1094 | 685 Usually one <command>tsmon</command> command program is started up concurrently for |
144 | 686 each terminal in the system. This is a special program which |
687 monitors a terminal for activity. When a carriage return character | |
1094 | 688 is typed on any of these terminals, the <command>tsmon</command> command initiates the |
689 <command>login</command> command program. If a user does not enter a correct password | |
690 or user number in three tries, the <command>login</command> command will be aborted. | |
144 | 691 Here's a sample procedure file for a 4-terminal timesharing system |
1094 | 692 having terminals names <quote>TERM</quote>, <quote>T1</quote>, |
693 <quote>T2</quote>, and <quote>T3</quote>. | |
144 | 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> | |
1094 | 705 NOTE: This <command>login</command> procedure will not work until a password file |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
706 called <filename>/DD/SYS/PASSWORD</filename> has been created. For more information, |
1094 | 707 please see the <command>login</command> command description. |
144 | 708 </para> |
709 <para> | |
710 The example above deserves special attention. Note that the | |
1053
b5ff125a1d60
Since this book was only typeset in fixed width, single-font, they used
roug
parents:
1014
diff
changeset
|
711 <command>setime</command> command has its input redirected to the system console |
144 | 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> |