Running a Rexx Program

Rexx programs should have a file extension of &per;cmd (the default searched for by the ooRexx interpreter). Here is a typical Rexx program named greeting&per;cmd. It prompts the user to type in a name and then displays a personalized greeting:

/* greeting&per;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 */

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. In this case, the message is the literal string "Please enter your name.". The data between the quotes is a constant and will appear exactly as typed. You can use either single (') or double quote (") delimiters for literal strings.

The PULL instruction reads a line of text from the standard input (the keyboard), and returns the text in the variable specified with 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 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 the operation system command prompt. EXIT can also return a value. In our example, 0 is returned. The EXIT instruction is optional. Running off the end of the program is equivalent to coding "EXIT 0".

You can terminate a running Rexx program by pressing the Ctrl+Break key combination. Rexx stops running the program and control returns to the command prompt.