Note: The following material was developed by Claude Cantin of the Research Computing Support Group of the National Research Council of Canada, and is used with his permission.

Special Characters

As with the Bourne shell features already covered, scripts:

In addition to the above-mentioned, scripts may also contain C and Bourne shell features.

'...': Turn off Meaning of Special Characters.

Single quotes are used within the shell and within the scripts to turn off the meaning of special characters, including spaces. A dollar sign ($) will normally be interpreted as a dollar sign, not the content of the variable following that $ sign.

For example,

VARI=me
echo $VARI
me
echo '$VARI'
$VARI

"...": Turn off Meaning of Special Characters EXCEPT $ and `

Within double quotes, all special characters are interpreted as their ASCII characters (not what they represent). This excludes the dollar sign ($) and the back quote (`).

Adding to the above example,

echo VARI = $VARI
VARI = me
echo "VARI = $VARI"
VARI = me

NOTE the spaces in the above example: they are printed as seen (spaces are significant within quotes).


`...`: Use Output as Content of Variable

To give a variable the value of the output of a command, one uses back quotes:

VARI="me"
echo $VARI
me
OTHER=`echo $VARI`
echo $OTHER
me

The output of the command within the back quotes is taken to be the new content of the first variable. Another short example: TODAY=`date`
echo $TODAY
Mon Aug 20 17:35:51 EDT 1990
echo "today's date is $TODAY"
today's date is Mon Aug 20 17:35:51 EDT 1990

Note that by default, the output of a series of commands is sent to the standard output. If the output is preceded by an = sign, the variable preceding the equal sign takes the value of the output of the command.