Quotes in Shell

Source: Internet
Author: User

From: http://www.lampchina.net/article/htmls/200903/MjE4Njk1.html

 

 

Function of quotation marks

1Double quotation marks ("")

1) Use""Referable except characters$ (Dollar sign),`(Reverse quotation marks ),/Any character or string outside (backslash. Double quotation marks are not blockedShellPerform special processing on the three characters (variable name, command replacement, and backslash escape ).

Example:

Name = gezn; echo "User name: $ name "//PrintUser name: gezn

Echo "The date is: 'date + date-% d-% m-% y '"//PrintThe date is:03-05-2009

Echo-e "$ USER/t $ UID "//PrintGezn 1, 500

2) Double quotation marks are frequently used for searching strings containing spaces.

 


2Single quotes ('')

1)If a string is enclosed in single quotesDayi9nhaoThe special meanings of any special characters in the string are blocked.

2)Example:

Echo-e '$ USER/t $ uid '//Print$ USER $ UID (Not blocked/T,Because the option"-E")

Echo 'user/t $ uid '//Print$ USER/t $ UID

 


3Back quotes ('')

1)ShellUse the content in the quotation marks as a system command and execute the content. This method can replace the output with a variable.

2)Example:

A = 'date + date-% d-% m-% y '//PrintThe date is:03-05-2009

 


4Backslash (/)

1) If the next character has a special meaning, the backslash preventsShellMisunderstanding its meaning, that is, shielding its special meaning.

2) Subordinate characters have special meanings:& * + $ '|?

3)Add the octal character (ASCIIThe backslash must be added to the front. OtherwiseShellAs a common number.

Example:

Bj = Beijing; echo "variable/$ bj = $ bj "//PrintVariable $ bj = beijing

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.