同步阅读进度,多语言翻译,过滤屏幕蓝光,评论分享,更多完整功能,更好读书体验,试试 阅读 ‧ 电子书库
Quoting
You can think of quoting as a way of getting the shell to skip some of the 12 steps above. In particular:
Single quotes (`') bypass everything through Step 10—including aliasing. All characters inside a pair of single quotes are untouched. You can't have single quotes inside single quotes—not even if you precede them with backslashes.
[8] Double quotes ("") bypass Steps 1 through 4, plus steps 9 and 10. That is, they ignore pipe characters, aliases, tilde substitution, wildcard expansion, and splitting into words via delimiters (e.g., blanks) inside the double quotes. Single quotes inside double quotes have no effect. But double quotes do allow parameter substitution, command substitution, and arithmetic expression evaluation. You can include a double quote inside a double-quoted string by preceding it with a backslash (
\). You must also backslash-escape
$,
` (the archaic command substitution delimiter), and
\ itself.
Table 7-7 has simple examples to show how these work; they assume the statement person=hatter was run and user alice's home directory is /home/alice.
If you are wondering whether to use single or double quotes in a particular shell programming situation, it is safest to use single quotes unless you specifically need parameter, command, or arithmetic substitution.
Table 7-7. Examples of quoting rules
Expression
Value
$person
hatter
"$person"
hatter
\$person
$person
`$person'
$person
"'$person'"
'hatter'
~alice
/home/alice
"~alice"
~alice
`~alice'
~alice