Creating and Editing a Source Program

The first step in developing a GT.M program is to create a source file. In most cases, the user can create and modify GT.M source programs using UNIX text editors.

When the program is very simple (and its lines do not need revision after they are entered), you can use the cat command to direct input from your terminal to your source file.

Editing from GT.M

If you focus on program development outside the GT.M environment, skip this section and continue with the section "Editing from the Shell".

ZEDIT <filename>

Invoke Direct Mode to create and edit a source program in GT.M. At the GTM> prompt, invoke the editor by typing:

ZEDIT <filename>

ZEDIT invokes the editor specified by the EDITOR environment variable, which creates a seperate file for each M source module.

The GT.M environment works most efficiently if the file has the same name as the M routine it contains, and has an .m extension. Since ZEDIT automatically defaults the.m extension, it is not necessary to specify an extension unless you require a different one. If you use another extension, you must specify that extension with every reference to the file. Multiple character file extensions are permitted for M source file names.


$ /usr/lib/.fis-gtm/V5.4-002B_x86/gtm
GTM>ZEDIT "payroll"

This syntax uses the gtm script to enter GT.M from the shell, and uses ZEDIT to initiate an editing session on payroll.m Because ZEDIT defaults the extension to .m, it is not necessary to provide an extension. If payroll.m does not already exist, GT.M creates it in the first source directory identified by $ZROUTINES. If $ZROUTINES is null, ZEDIT places the source file in the process's current working directory.

$ZROUTINES is a read-write special variable containing an ordered list of directories that certain GT.M functions use to locate source and object files. Generally, a system manager sets up the environment to define the environment variable gtmroutines. At image invocation, GT.M initializes $ZROUTINES to the value of gtmroutines. Once you are running M, you can SET and refer to $ZROUTINES using the format:



  • The expression may contain a list of UNIX directories and/or file-specifications delimited by spaces.

  • The expression specifies one or more directories to search.

  • An element of the expression contains an environment variable evaluating to a directory specification.

  • If $ZROUTINES contains an environment variable that evaluates to a list, GT.M uses the first name in that list.

For more information on $ZROUTINES, see Chapter 8: “Intrinsic Special Variables.

Editing from the Shell

To create and edit a source program from the shell, invoke any text editor at the shell prompt and specify a UNIX file as the source. The GT.M environment works best when you give a file the name of the M routine that it contains, and an .m extension.


$ vi payroll.m

The vi command initiates an editing session for payroll.m from the shell prompt. If payroll.m does not already exist, vi creates it. Because this example uses UNIX rather than GT.M tools, we must specify the .m file extension.