Introducing UNIX and Linux |
Processes and devicesOverview |
Quotes and escapesA number of characters are understood by the shell to have a
special meaning, such as
If you wish to use any of these characters in any context other than the shell defines for them, they must be either quoted or escaped. In general, if it's a single character, preceding it with a backslash will indicate that its literal value is to be used. Alternatively, if there are several such characters, enclose the whole string in single quotes:
There are two important points here that you need to remember. First of all, the shell strips off pairs of quotes, and matches an opening quote with its nearest possible closing match, so:
This implies that a single quote cannot occur within a quoted string that is quoted using single quotes. The second point is that quotes must come in pairs. Notice what happens if they don't:
At the end of the first line the shell is looking for a single
quote; not having found one, it assumes that the Newline
character you entered when you typed Return is part of the
string, that you intended a space instead, and that you wish to
continue entering the rest of the string. The
The newline is not part of the string, and is replaced by a space Double quotes can be used in the same way as single quotes,
except that not all characters enclosed between them become
literal. In particular, variable names preceded by
Without quotes, the shell would assign
If a read-only variable has been exported, it will not be read-only for any child processes - 'read-only-ness' is not exportable. |
Copyright © 2002 Mike Joy, Stephen Jarvis and Michael Luck