[ Previous | Next | Contents | Glossary | Home | Search ]
AIX Version 4.3 System User's Guide: Operating System and Devices

Quoting

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 quotes, and double quotes.

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

A backslash cannot be used to escape a single quote in a single-quoted string. An embedded quote can be created by writing, for example: 'a'\''b', which yields a'b.

Double Quotes Enclosing characters in double quotes (" ") preserves the literal value of all characters within the double quotes, with the exception of the characters dollar sign, backquote, and backslash, 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 quotes, 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 quotes or single quotes, 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 new-line character.

A double quote must be preceded by a backslash to be included within double quotes. When you use double quotes, 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:


[ Previous | Next | Contents | Glossary | Home | Search ]