Quoting Quotation Marks

You can also use a backslash to include double quotes within a quoted string. For example:

$ echo \"2 \* 3 \> 5\" is a valid inequality.

广告:个人专属 VPN,独立 IP,无限流量,多机房切换,还可以屏蔽广告和恶意软件,每月最低仅 5 美元

produces the following output:

"2 * 3 > 5" is a valid inequality.

However, this won't work with single quotes inside quoted expressions. For example, echo `Hatter\'s tea party' will not give you Hatter's tea party. You can get around this limitation in various ways. First, try eliminating the quotes:

$ echo Hatter\'s tea party

If no other characters are special (as is the case here), this works. Otherwise, you can use the following command:

$ echo 'Hatter'\''s tea party'

That is, `\'' (i.e., single quote, backslash, single quote, single quote) acts like a single quote within a quoted string. Why? The first ' in `\'' ends the quoted string we started with (`Hatter), the \' inserts a literal single quote, and the next ' starts another quoted string that ends with the word "party". If you understand this, then you will have no trouble resolving the other bewildering issues that arise from the shell's often cryptic syntax.