Using Quotation Marks

The rules for forming a command from an expression are the same as those for forming expressions. Be careful with symbols that are used in Rexx and Windows programs. The dir&per;cmd program below shows how Rexx evaluates a command when the command name and a variable name are the same:

dir&per;cmd (Windows)
/* dir&per;cmd - assign a value to the symbol DIR */
say "DIR command using Rexx"
dir = "echo This is not a directory."
/* pass the evaluated variable to Windows */

Because dir is a variable that contains a string, the string is passed to the system. The DIR command is not executed. Here are the results:

[C:\\]rexx dir&per;cmd
DIR command using Rexx:
This is not a directory.

Rexx evaluates a literal string--a string enclosed in matching quotation marks--exactly as it is. To ensure that a symbol in a command is not evaluated as a variable, enclose it in matching quotation marks as follows:

Passing values to command environments
/* assign a value to the symbol DIR */
say "DIR command using Rexx"
dir = "echo This is another string now."
/* pass the literal string "dir" to Windows */

Rexx displays a directory listing.

The best way to ensure that Rexx passes a string to the system as a command is to enclose the entire clause in quotation marks. This is especially important when you use symbols that Rexx uses as operators.

If you want to use a variable in the command string, leave the variable outside the quotation marks. For example:

extension = "BAK"
option = "/w"
"dir" option