UNIX for OpenVMS Users, Second Edition

The result of variable expansion depends on whether the variable is surrounded by single forward quotes, double quotes, or single backward quotes. A single forward quote prevents any kind of variable expansion (compare OpenVMS variable name only). The variable name is returned literally, and alias or wildcard expansion does not take place. A double quote groups characters or numbers into a single argument (as shown above), allows variable expansion, and prevents wildcard expansion (compare OpenVMS double quotes). A single backward quote causes the immediate execution of a command argument (available under OpenVMS only if the symbol is the first word on a command line). The following example illustrates these three kinds of variable expansion.
| OpenVMS | UNIX (C shell) | |
|---|---|---|
| Example: | $ <b class="bold">NAME ="DIR *.FOR"</b>$ <b class="bold">WRITE SYS$OUTPUT "NAME"</b>NAME$ <b class="bold">WRITE SYS$OUTPUT NAME</b>DIR *.FOR$ <b class="bold">'NAME'</b>PROGRAM.FOR | % <b class="bold">set name = "ls *.f"</b>% <b class="bold">echo $name</b>ls program.f% <b class="bold">echo '$name'</b>$name% <b class="bold">echo "$name"</b>ls *.f% <b class="bold">echo '$name'</b>program.f |
The command echo $name returns the variable substitution with the metacharacter expanded, whereas echo '$name' prevents any variable substitution and returns the variable name. The command echo "$name" returns the substitution for the variable name, which includes the nonexpanded metacharacter *. Finally, echo '$name' causes immediate command execution: the result of executing the command between backward quotes becomes part of the command line. The command Is *.f indicates that one file of the file type .f, program.f, resides in the present working directory.