REXX looks a lot like PL/1.
Table of contents |
2 Syntax 3 Under OS/2 |
Originally a scripting language developed at IBM. REXX was the successor to the script languages EXEC and EXEC 2.
It was also designed to be a macro or scripting language for any system. As such, it is a precursor to TCL and Python.
Over the years IBM developed versions for many of its operating systems: VM/CMS, OS/2, PC-DOS, MVS/TSO, AS/400, and AIX. Non-IBM versions have also been developed for Atari, Unix, DEC, Windows, and MS-DOS. Later versions of the Amiga OS included a version of REXX called AREXX.
Several freeware versions are available. REXX/IMC and Regina are the most widely-used open-source ports to Windows and Linux.
In 1996 ANSI published a standard for REXX:
ANSI X3.274-1996 "Information Technology - Programming Language REXX"
In recent years, two newer variants of REXX have appeared:
The DO control structure always begins with a DO and ends with an END.
DO UNTIL:
DO WHILE:
Stepping through a variable:
Looping forever until exiting with LEAVE:
Looping a fixed number of times
Testing conditions with IF
For single instructions, DO and END can also be omitted:
SELECT is REXX's CASE structure
NOP indicates no instruction is to be executed.
The PARSE instruction is particularly powerful; it combines some useful string-handling functions. Its syntax is:
where origin specifies the source:
Examples:
Using a list of variables as template
displays the following
Using a delimiter as template:
also displays the following
Using column number delimiters:
displays the following
A template can use a combination of variables, literal delimiters, and column number delimiters.
REXX is included in the base operating system of OS/2, and is also used as the macro language in many applications.
Under OS/2, a REXX program begins with matched comment delineaters, /* */, to indicate to the OS that it is a REXX program:
Instructions between quotes are passed to the OS:
Cowlishaw seems to prefer Rexx, whereas IBM sales, ANSI, and the majority of the web uses REXX.
History
Syntax
Looping
do until [condition]
[instructions]
end
do while [condition is true]
[instructions]
end
do i = x to y by z
[instructions]
end
do forever
if [condition] then leave
end
do i = x to y by z for a
[instructions]
end
Conditionals
if [condition] then
do
[instructions]
end
else
do
[instructions]
end
if [condition] then
[instruction]
else
[instruction]
Testing for multiple conditions
select
when [condition] then
do
[instruction]
end
otherwise
do
[instruction] or NOP
end
PARSE
parse [upper] origin template
and template can be:
upper is optional; it you specify it, data will be converted to upper case. myVar = "John Smith"
parse var MyVar firstName lastName
say "First name is:" firstName
say "Last name is:" lastName
First name is: John
Last name is: Smith
myVar = "Smith, John"
parse var MyVar LastName "," FirstName
say "First name is:" firstName
say "Last name is:" lastName
First name is: John
Last name is: Smith
myVar = "(202) 123-1234"
parse var MyVar 2 AreaCode 5 7 SubNumber
say "Area code is:" AreaCode
say "Subscriber number is:" SubNumber
Area code is: 202
Subscriber number is: 123-1234
Under OS/2
/* sample.cmd */
say "Hello World"
/* sample.cmd */
'dir /p /w'
Spelling
External Links