Here we expand on the S/REXX extensions to the traditional REXX language and environment which are designed to make REXX more comfortable for UNIX users.
With most REXX implementations, REXX procedures implemented in external files cannot share global variables with the main procedure or each other. S/REXX can dynamically load external procedures by logically appending them to the end of the main file. Such procedures become internal procedures and follow normal REXX rules for variable sharing between procedures in a single file. This facility allows the building of a collection of general utility routines which are incorporated as needed. Therefore, variable sharing can be achieved without creating a pseudo-compile phase which would preprocess REXX programs recognizing an include type of directive.
Enclosing a REXX string expression in backquotes will cause the value of the expression to be executed as a UNIX command with the command's STDOUT returned as the string value of the backquoted expression.
The new DO iterator IN will execute the loop once fore each word in the object expression:
do VAR1 in EXPR is equivalent to do IW = 1 to words(EXPR)
say VAR1 say word(EXPR,IW)
end end
The alternative offered by S/REXX while not much simpler is more obvious to
users experienced with traditional UNIX scripting languages. Its value becomes
more obvious in this example:
WRK = `"ls"`
do FILE in `"ls"` do FI = 1 to words(WRK)
parse var FILE FN "." FT . parse value word(WRK,FI) with FN "." FT .
if FT = 'c' then say FN if FT = 'c' then say FN
end end
Brackets may be used to replace several traditional REXX uses of the substr() built-in function to set or access sub-strings.
xxxx[i1{:i2}]
is the general form supported where i1 represents the first character in string
xxxx referenced and i2 the optional last character referenced. The
default is i2=i1 if i2 is omitted.
The following example compares the S/REXX extension with TRL REXX specified by Cowlishaw:
S/REXX: abcd[7:10] = "WxYzQde" TRL: abcd = substr(abcd,1,6) || "WxYz" || substr(abcd,11)
A number of REXX built-in functions have been extended and a large number of new built-in functions implemented to ease the interface with UNIX system facilities. You are encouraged to download and try S/REXX or examine the documentation files for many more details. This page will simply list the new or extended built-in functions.