Quotation of characters 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.
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:
- pipe (
|
) - ampersand (
&
) - semicolon (
;
) - less-than sign (
<
) and greater-than sign (>
) - left parenthesis (
(
) and right parenthesis ()
) - dollar sign (
$
) - backquote (`) and single quotation mark (
'
) - backslash (
\
) - double-quotation marks (
"
) - newline character
- space character
- tab character
To negate the special meaning of a metacharacter, use one of the quoting mechanisms in the following list.
Item | Description |
---|---|
Backslash | A backslash (\ ) that is not quoted preserves
the literal value of the following character, with the exception of a newline
character. If a newline character follows the backslash, then 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 |
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:
|
"\$" -> $
"\a" -> \a
- The meanings of dollar sign, asterisk (
$*
) and dollar sign, at symbol ($@
) are identical when not quoted, when used as a parameter assignment value, or when used as a file name. - When used as a command argument, double quotation marks, dollar sign,
asterisk, double quotation marks (
"$*"
) is equivalent to"$1d$2d..."
, where d is the first character of the IFS parameter. - Double quotation marks, at symbol, asterisk, double quotation marks (
"$@"
) are equivalent to"$1" "$2" ...
. - Inside backquotes (
``
), the backslash quotes the characters backslash (\
), single quotation mark ('
), and dollar sign ($
). If the backquotes occur within double quotation marks (" "
), the backslash also quotes the double quotation marks character. - Parameter and command substitution occurs inside double quotation marks
(
" "
). - The special meaning of reserved words or aliases is removed by quoting any character of the reserved word. You cannot quote function names or built-in command names.