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 DIRREX.CMD program below shows how Rexx evaluates a command when the command name and a variable name are the same:

/* DIRREX.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         */
dir

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 dirrex
DIR command using Rexx:
This is not a directory.
[C:\]

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:

/* 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 */
"dir"

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"
"delete *."||extension

option = "/w"
"dir"||option