REXX programs on OS/2 should have a file extension of CMD, just like Batch facility files. Here is a typical REXX program named GREETING.CMD. It prompts the user to type in a name and then displays a personalized greeting:
/* GREETING.CMD -- a REXX program to display a greeting. */ say 'Please enter your name.' /* Display a message */ pull name /* Read response */ say 'Hello' name /* Display greeting */ exit 0 /* Exit with a return code of 0 */
Notice that the program begins with a comment. In OS/2, the first line of a REXX program must start with a comment in column 1. If you omit the comment, OS/2 thinks the program is a Batch facility program, and will try to run it as such. Naturally, all sorts of errors will result.
SAY is a REXX instruction that displays a message (like PRINT in Basic or printf in C). The message to be displayed follows the SAY keyword. The single quotes are necessary to delimit a character string. In this case, the character string is Please enter your name. You can use double quotes (") instead of single quotes if you wish.
The PULL instruction reads a line of text from the standard input (the keyboard), and returns the text in the variable specified on the instruction. In our example, the text is returned in the variable name.
The next SAY instruction provides a glimpse of what can be done with REXX strings. It displays the word "Hello" followed by the name of the user, which is stored in variable name. REXX substitutes the value of name in the expression and displays the resulting string. You do not need a separate format string as you do with C or Basic.
The final instruction, EXIT, ends the REXX program. Control returns to OS/2. EXIT can also return a value. In our example, zero is returned. The EXIT instruction is optional.
You run a REXX program just as you would run a Batch facility program. Type the file name of the program at an OS/2 command prompt. OS/2 follows its usual search rules when trying to find the program. That is, OS/2 looks for the program in the current directory. If OS/2 cannot find the command, it searches the directories listed in the PATH environment variable.
You can stop a REXX program by pressing the Control (Ctrl)+Break keys. REXX stops running the program and control returns to OS/2.