UNIX for OpenVMS Users, Third Edition

The result of variable expansion depends on whether the variable is surrounded by single forward quotes (a.k.a. strong quotes), double quotes (a.k.a. weak quotes), or single backward quotes (a.k.a. backticks). A string delimited with the single forward quote character prevents any kind of variable expansion or metacharacter interpretation (compare with the variable name only in OpenVMS). The variable name is returned literally, and alias or wildcard expansion does not take place. A string delimited with the double-quote character also groups characters or numbers into a single argument (as shown above), but it allows variable expansion, while still preventing wildcard expansion (compare with the double quotes in OpenVMS). A string delimited with the single backward quote character also performs variable expansion, but in addition, allows wildcard expansion and then causes the resulting string to be executed as a command (available under OpenVMS only if the symbol is the first word on a command line). The example below illustrates these three kinds of variable expansion.
| OpenVMS | UNIX (C Shell) |
|---|---|
| Example: | |
|
$ NAME ='DIR *.FOR'$ WRITE SYS$OUTPUT 'NAME' NAME$ WRITE SYS$OUTPUT NAMEDIR *.FOR$ 'NAME'PROGRAM.FOR |
% set name = "ls *.f"% echo $namels program.f% echo '$name' $name% echo "$name"ls *.f% echo `$name`program.f |
| Perl | |
| Example: | |
|
$ cat quotes.pl#!/usr/bin/perl -w# Quote demo$name = "ls *.f";print '$name', "\n";print "$name\n";print `$name`;exit;$ ./quotes.pl$namels *.fprogram.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