Applix 1616 — Applix 1616 User Tutorial: Руководство для начинающих (PDF)

Executing shell program files When you execute a .shell file, by typing its name (without the .shell exten- sion), lines from it are read and executed as if they had been typed from the keyboard. Control is returned to the keyboard when the file is exhausted. Comments may be put in .shell files. They are preceded by a semicolon. Any arguments following the command file name are substituted into special symbols within the lines before they are executed. The special symbol ‘ ’ refers to the first argument, ‘ ’ to the second, etc. The ‘ ’ symbol returns the name of the shell file itself. The symbol ‘ ’ refers to all arguments except the name of the shell file (arguments 1 and on).

Two very simple and silly examples of .shell files: ; A shell program to rename a file ; Usage: ren oldname newname rename $1 $2 ; Pass the arguments on to the OS ; A shell program to delete files like MS-DOS! ; Usage: del file1 file2 file3 .... delete $* ; Delete all the files specified You should carefully examine the various shell files on your User disk, and on the various Applix freeware disks for more extensive ‘real’ examples of how to use these files. If readers pester me about this, I’ll find some better examples. Shell file error trapping and command echoing There are five commands which are only allowed within shell programs.

The commands trap and notrap enable and disable error trapping mode. The com- mands ‘ + ’ and ‘ - ’ enable and disable command echoing mode. If no commands are specified then error trapping and echoing both default to the disabled state. Error trapping mode If a shell program is executing in error trapping mode (by placing a trap command early in the file), and it executes an inbuilt or transient command which flags an error, then the shell program will be terminated. Errors are indicated by returning a negative number in the MC68000’s d0 register, as described in the Programmer’sManual . Allinbuiltcommandsflagerrorsifsomethinggoeswrong.

Correctly written transient programs should return an error flag if they detect some form of failure. The command trap 2 in a shell file causes it to exit if a command returns any non-zero exit status. This differs from the normal trap command, which only traps a negative exit code. The new addition to Version 4 is designed for programs ported from U NIX , where error exit codes are anything non-zero. The HiTech C compiler passes normally return non-negative exit codes, so it is of use here. Starting Programs User Tutorial Manual Page 41