Quoting in the shell

Source: Internet
Author: User

The quoting (reference) in the shell can be used to remove the special meaning of a character so that it retains its literal meaning and can be used for a variety of shell Expansion.


There are 3 kinds of quoting mechanisms: escape characters, single quotes, and double quotes.



1. Escape character

A non-referenced backslash ' \ ' is called an escape character, and it retains the literal meaning of the subsequent single character (removing the special meaning). With the exception of the backslash as the last character of the input line, the shell treats it as a continuation character, removes the subsequent newline character, and does not use the newline character as the delimiter for the parameter, as if the character had not occurred.



2. Single quotation marks

All the characters in the single quote ' ' will retain their literal meaning. Note that a single quotation mark cannot appear in the middle of a two single quotation mark, even if it is preceded by a backslash.



3. Double quotes

Double quotes in addition to the 4 characters ' $ ', ' ', ' \ ' and '! ' Outside, the others remain literal (note that the shell is in POSIX mode, '! ') also maintain literal meaning).


The characters ' $ ' and ' will carry out shell Expansion (such as variable expansion, command substitution, etc.).


Backslash ' \ ' in ' $ ', ' ', ' ' ', ' \ ', and newline in front, it will be removed, followed by the character unchanged, meaning literal.


In the expansion, '! ' You need to add ' \ ' before you can suppress the extension, and ' \ ' will not be removed.



Also, to understand the special ansi-c quoting, in the form of $ ' string ', the backslash ' \ ' in string and subsequent characters will be escaped in accordance with ANSI C standard, the result is like the ' $ ' symbol does not exist, only use single quotation marks. How to use ansi-c quoting, see in bash programming the variable has the Matchless quotation mark Quest.


If interested, you can follow the subscription number "database Best practices" (Dbbestpractice).

Quoting in the shell

Related Article

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.