Quote-double quotation marks, single quotes, and escape characters

Source: Internet
Author: User
Shell provides a reference mechanism to selectively avoid unwanted extensions.

Introduction

Shell provides a reference mechanism to selectively avoid unwanted extensions.

============================================

Double quotation marks

If the text is placed in double quotation marks, all special characters used by shell will lose their special meaning and be considered as common characters.

Except for characters $ (dollar sign), \ (backslash), and '(quotation marks.

This means that the path extension, wave first extension, and curly braces extension will all expire. However, parameter extension, arithmetic extension, and command replacement are valid.

Example 1 (the PATH extension is invalid)

[Root @ allyes20121031 de_info_center] # echo "*"

*

Example 2 (effective command replacement)

[Root @ allyes20121031 de_info_center] # echo "$ (ls )"

2. txt

Argv. cpp

Argv. h

Config. cpp

Double quotation marks are applicable when the file name contains white spaces.

Assume that there is unfortunately a file named two words.txt. If this file name is used in the command line, the word segmentation function treats them as two independent parameters.

Double quotation marks can prevent word segmentation.

============================================

Single quotes

If we want to suppress all extensions, we should use single quotes.

For example

[Root @ allyes20121031 de_info_center] # echo "$ (ls )"

2. txt

Argv. cpp

Argv. h

Config. cpp

[Root @ allyes20121031 de_info_center] # echo '$ (ls )'

$ (Ls)

[Root @ allyes20121031 de_info_center] #

============================================

Escape characters

Sometimes we just want to reference a single referenced character. In this case, you can add a backslash before the character.

For example

[Root @ allyes20121031 de_info_center] # echo "$ (ls )"

2. txt

Argv. cpp

Argv. h

Config. cpp

[Root @ allyes20121031 de_info_center] # echo "\ $ (ls )"

$ (Ls)

[Root @ allyes20121031 de_info_center] #

Escape characters are also used to remove the special meaning of a character in a file name.

These characters include "$" and ","! "," & ", And space.

============================================

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.