We shall write the following REXX procedure using a text editor. To write a REXX procedure named HELLO.CMD while using the text editor follow these instructions:
/* An introduction to REXX */ SAY "Hello! I am REXX" SAY "What is your name?" PULL who IF who = "" THEN SAY "Hello Stranger" ELSE SAY "Hello" who EXIT
Now you are ready to run the REXX procedure you have written. Type the name of the procedure at the OS/2 command prompt and press Enter.
hello
When the procedure pauses, you can either type your name or press Enter to see the other response.
A brief description of each part of HELLO.CMD follows:
/* An introduction to REXX */ A comment explains what the procedure is about. A comment starts with a /* and ends with a */. All REXX procedures must start with a comment on line one and column one of the file. The comment tells the command processor that the procedure being run is a REXX procedure and distinguishes it from simple batch files.
SAY "Hello! I am REXX." SAY "What is your name?" These instructions cause the words between the quotation marks to be displayed on your screen.
PULL who The PULL instruction reads the response entered from the keyboard and puts it into the system's memory. Who is the name of the place in memory where the user's response is put. Any name can be used with the PULL instruction.
IF who = " " The IF instruction tests a condition. The test in this example determines if who is empty. It is empty if the user types a space and presses Enter or just presses Enter.
THEN Specifies that the instruction that follows is to be run, if the tested condition is true.
SAY "Hello Stranger" Displays Hello Stranger on the screen.
ELSE Specifies that the instruction that follows is to be run if the tested condition is not true.
SAY "Hello" who Displays Hello on the screen, followed by whatever is in who.
EXIT This instruction causes the procedure to stop.
Here is what would happen if a person named Bill tried the HELLO program:
[C:\]hello Hello! I am REXX. What is your name? Bill Hello BILL [C:\]If Bill does not type his name, but types a blank space, this happens:
[C:\]hello Hello! I am REXX. What is your name? Hello Stranger [C:\]