Quoting variable values
When you have blanks in a variable value, you need to enclose it
in quotation marks. The quotation marks tell the shell to treat blanks
as literals and not delimiters. Single quotation marks are more serious
about this than are double quotation marks:
- Single quotation marks preserve the meaning of (that is, treat literally) all characters.
- Double quotation marks still allow certain characters ($, ` (back quote), and \ (backslash)) to
be expanded. This is important if you want variable expansion. For example, see how the $ is handled
here:
If your home directory were set to /u/user, the following:export HOMEMSG="Using $HOME as Home Directory"
would display:echo $HOMEMSG
If, instead, you enclosed the variable value in single quotation marks, like this:Using /u/user as home directory
the following line:export HOMEMSG='Using $HOME as home directory'
would display:echo $HOMEMSG
As you can see, the $ is not expanded.Using $HOME as home directory