Single quotes in Linux commands, with no arguments and double quotes

Source: Internet
Author: User

Single quotes:

What you can say is what you see is what you get: the contents of a single quotation mark are output as-is, or what you see in single quotes is what you output. The single quotation mark ' is a full reference, and the contents of the enclosed quotation mark do not occur if the constant or the variable is substituted.

Double quotes:

The contents of the double quotation marks are output, and if there are commands, variables, etc., the variables, commands are parsed out and then the final content is output. The double quotation mark "" is a partial reference, the content constant or constant that is enclosed in double quotation marks, and the variable is replaced with the variable content.

No quotes:

does not consider the string containing the space as a whole output, if the content has commands, variables, etc., will first parse the variables, commands, and then in the output of the final content, if the string with a space and other special characters, it is not complete output, need to add double quotation marks, general continuous string, number, path, etc. can be used.

Usage Rules:

The general constants are enclosed in single quotation marks, if the containing variable is enclosed in double quotation marks.

Maximum difference:

The maximum difference between a single quote and a double quote is that the double quotation marks can still hold the contents of the variable, but the single quote can only be a generic word

The yuan, without special symbols

Examples of Use:

"" In the number of $,\ and other special words inode for the corresponding variable substitution

All the characters inside the ' sign are intact.

For strings, the two are the same

The matching pattern is roughly the same

But there are some differences that are very easy to confuse

grep "$a" file #引用变量a to find the value of variable a

grep ' $a ' file #查找 ' $a ' string

grep "\ \" File #grep: Trailing backslash (unknown reason)

grep ' \ \ ' file #查找 ' \ ' character

1, $ dollar symbol

2, \ anti-slash

3, ' anti-quote

4, "double quotes

These four characters have special meanings in double quotes, others do not, and single quotes make all characters lose special meanings

If you look up a \ In double quotes, you should use four \:

grep "\\\\" File This is true, this is equivalent to:

grep ' \ \ ' file

The first command shell four \, escaped into 2 \ Pass to Grep,grep and then 2 \ escaped into a \ Lookup

The second command shell is not escaped, directly to the 2 \ Pass to the grep,grep and then 2 \ escaped into a \ Lookup

In fact, grep executes the same command.

Original address: http://blog.csdn.net/cupidove/article/details/8783968

Single quotes in Linux commands, with no arguments and double quotes

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.