Leveraging the UNIX Environment

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.

Dynamic loading of external procedures

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.

Traditional use of backquote (`) to retrieve the result of executing UNIX commands

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.

A new DO instruction iterator to control loop interation based on the number of words in an 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

Square bracket ([]) indexing of character strings

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)

Many new built-in functions access UNIX facilities

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.

arch
Get hardware information
arg
Returns argument string, including name of the S/REXX program
change
Change string
charin
Will read a specified number of characters without display
chdir
Change directory
csh
Pass UNIX command to the C shell
cuserid, userid
Get userid (login name of the user)
cwd, getcwd, getwd
Get current directory
date
date('j') gives julian date
dy_button
Make a dialog button item
dy_ch
Make a choice dialog item
dy_destroy
Destroy a dialog box
dy_end
End a dialog box
dy_input
Make a dialog input item
dy_label
Make a dialog label item
dy_map
Map a dialog box
dy_sinput
Set a dialog input item value
dy_start
Start a dialog box
dy_stg
Set a dialog toggle value
dy_tg
Make a dialog toggle
dy_unmap
Unmap a dialog box
dy_vinput
Get a dialog input item value
dy_vch
Get a dialog choice value
dy_vtg
Get a dialog toggle item value
externals
Returns the number of characters available in the standard input stream
fd
Get filename directory part
fn
Get filename name part
ft
Get filename type part
getenv
Get environment variable
ksh
Pass UNIX command to the Korn shell
linein, lineout
Input / Output -- see the documentation for extensions
mkdir
Make a directory
parg
Parse argument - provides UNIX command line argument handling
rm
Remove (delete or unlink) a file
setenv, putenv
Set environment variable
sleep
Suspend execution for specified seconds
state
Query file state -- check existance and attributes of filess
tbadd
Insert a line in an ISPF like table
tbclose
Close an ISPF like table
tbdel
Delete table line
tbdispl
Display table
tbget
Get table line
tbopen
Open a table
tbput
Update a table line
tbsave
Save table
tee
Pass a command to UNIX displaying the intermediate results
unix, sh
Pass a UNIX command to the Bourne shell
unsetenv
Deletes the specified environment variable
usleep
Suspend execution for specified micro-seconds

Return to an Overview of Benaroya Products including SEDIT and S/REXX.