The role of quotation marks in the shell

Source: Internet
Author: User

The function of quotation marks

1 double quotation marks ("")

1) Use "" To reference any character or string except the character $ (dollar sign), ' (anti-quote), \ (backslash). Double quotation marks do not prevent the shell from special handling of these three characters (flag variable name, command substitution, backslash escape).

EG:NAME=GEZN; echo "User name: $name"//will print User NAME:GEZN

Echo "The date is: ' Date +date-%d-%m-%y '"//will print the date is:03-05-2009

Echo–e "$USER \t$uid"//will print GEZN 500

2) If you want to find new strings that contain spaces, you often use double quotes

2 single quotes (')

1) If you enclose the string in single quotation marks, the special meaning of any special character in the string within the Dayi9nhao is masked.

2) example: Echo–e ' $USER \t$uid '//will print the $user $UID (no shield \ t, because of the option "-e")

Echo ' User\t$uid '//will print $user\t$uid

3 anti-quote (')

1) the shell takes the contents of the inverted quotation mark as a system command and executes its contents. Use this method to replace the output to a variable

2) Example: a= ' date + date-%d-%m-%y '//will print the date is:03-05-2009

4. backslash (\)

1) If the next character has a special meaning, the backslash prevents the shell from misunderstanding its meaning, that is, shielding its special meaning.

2) subordinate characters contain special meanings:& * + $ ' "| ?

3) to add octal characters (ascii corresponding characters) when printing a string, you must precede it with a backslash, or the shell will be a normal number.

Example: bj=beijing; echo "variable\ $BJ = $BJ"//will print variable $BJ = Beijing

The effect of quotes in the shell (GO)

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.