Differences between single quotes and double quotes in Linux

Source: Internet
Author: User
When learning shell commands, it is often difficult to tell when to use double quotation marks and when to use single quotation marks, or think that there is no difference.
In fact, there are still differences:
Both single quotes and double quotes can disable shell processing for special characters. The difference is that double quotes do not have strict single quotes. Single quotes disable all characters with special functions, while double quotes only require shell to ignore the majority. Specifically, it is the dollar sign (②), the quotation mark (③), and The backslash. These three special characters are not ignored.
The dollar sign is not ignored, which means shell also replaces variable names in double quotes.

Example:
For example, if I define a variable name = Bane, the result of ECHO $ name is Bane;
Put the variable name in double quotes, for example, Echo "the name is $ name". The result is the name is
Bane.
Put the variable name in single quotes, for example, Echo 'the name is $ name'. The result is the name is
$ Name.

For comparison, the value of the variable is referenced in double quotation marks, while that in single quotation marks is a simple string!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.