You can use variables to build commands, just as you would use variables to construct any string. The SHOFIL.CMD program below is an example. SHOFIL types a file that the user specifies. It prompts the user to enter a file name and then builds a variable to hold the TYPE command and the input file name.
To have REXX issue the command to the operating system, put the variable holding the command string on a line by itself. REXX evaluates the variable and passes the resultant string to OS/2:
/* SHOFIL.CMD -- build command with variables */
/* prompt the user for a file name */
say "Type a file name:"
/* assign the response to variable FILENAME */
pull filename
/* build a command string by concatenation */
commandstr = "TYPE" filename
/* Assuming the user typed "demo.txt," */
/* the variable COMMANDSTR contains */
/* the string "TYPE DEMO.TXT" and so... */
commandstr /* ...REXX passes the */
/* string on to OS/2 */
REXX displays the following on the screen when you run the program.
[C:\]shofil Type a file name: demo.txt This is a sample text file. Its sole purpose is to demonstrate how commands can be issued from REXX programs. [C:\]