[ Bottom of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]

System User's Guide: Operating System and Devices

Quoting in the Korn Shell or POSIX Shell

When you want the Korn shell or POSIX shell to read a character as a regular character, rather than with any normally associated meaning, you must quote it. To negate the special meaning of a metacharacter, use one of the quoting mechanisms in the following list.

Each metacharacter has a special meaning to the shell and, unless quoted, causes termination of a word. The following characters are considered metacharacters by the Korn shell or POSIX shell and must be quoted if they are to represent themselves:

The quoting mechanisms are the backslash (\), single quotation mark ('), and double quotation marks (").

Backslash) A backslash (\) that is not quoted preserves the literal value of the following character, with the exception of a newline character. If a new-line character follows the backslash, the shell interprets this as line continuation.
Single Quotation Marks Enclosing characters in single quotation marks ( ' ') preserves the literal value of each character within the single quotation marks. A single quotation mark cannot occur within single quotation marks.

A backslash cannot be used to escape a single quotation mark in a string that is set in single-quotation marks. An embedded quotation mark can be created by writing, for example: 'a'\''b', which yields a'b.

Double Quotation Marks Enclosing characters in double quotation marks (" ") preserves the literal value of all characters within the double quotation marks, with the exception of the dollar sign, backquote, and backslash characters, as follows:
$
The dollar sign retains its special meaning introducing parameter expansion, a form of command substitution, and arithmetic expansion.

The input characters within the quoted string that are also enclosed between $( and the matching ) will not be affected by the double quotation marks, but define that command whose output replaces the $(...) when the word is expanded.

Within the string of characters from an enclosed ${ to the matching }, there must be an even number of unescaped double quotation marks or single quotation marks, if any. A preceding backslash character must be used to escape a literal { or }.

`
The backquote retains its special meaning introducing the other form of command substitution. The portion of the quoted string, from the initial backquote and the characters up to the next backquote that is not preceded by a backslash, defines that command whose output replaces ` ... ` when the word is expanded.
\
The backslash retains its special meaning as an escape character only when followed by one of the following characters: $, `, ", \, or a newline character.

A double quotation mark must be preceded by a backslash to be included within double quotation marks. When you use double quotation marks, if a backslash is immediately followed by a character that would be interpreted as having a special meaning, the backslash is deleted, and the subsequent character is taken literally. If a backslash does not precede a character that would have a special meaning, it is left in place unchanged, and the character immediately following it is also left unchanged. For example:

"\$"    ->      $
"\a"    ->      \a

The following conditions apply to metacharacters and quoting characters in the Korn or POSIX shell:

[ Top of Page | Previous Page | Next Page | Contents | Index | Library Home | Legal | Search ]