Three types of quotes in the Linux shell

Source: Internet
Author: User

There are three types of quotes in the Linux shell, double quotation marks (""), single quotation marks (' '), and anti-quotation marks (').

The double quotation marks replace the $, ', ', and \ that appear in the string, the single quotation marks are not replaced, all the characters in the string are output as ordinary characters, and the string in the anti-quotation marks executes as a shell command and returns the execution result. The specific meanings are as follows:

Double quotation marks (""): in double quotes, except $, ', ' and \ All characters nonalphanumeric are interpreted into the character itself.

Single quotation marks ("): all characters in single quotation marks including special characters ($, ', ' and \) are interpreted as characters themselves and become ordinary characters.

Anti-quote ('): The string in the anti-quote will be interpreted as a shell command to execute.

Example:

12 [email protected]:~# echo "$PATH" /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games

You can see that in double quotes, $ is treated as a special character, and path is interpreted as a variable.

[email protected]: ~# echo ' $PATH '

$PATH

In single quotes, special characters also lose their special meaning as normal character output.

[email protected]: ~# echo ls

Ls

LS is a shell command, and the direct echo LS shell outputs ls as a normal character. If we add an anti-quote, it's different.

[email protected]: ~# echo ' ls '

99.sh cloud_curr_design cloud_curr_design.tar.gz exefile for.sh gyb_virsh httpd-2.2.31 qemu_help readfile.sh switch.sh Temp temp10.sh temp1.sh temp2.sh temp3.sh temp4.sh temp5.sh temp6.sh temp7.sh temp8.sh temp9.sh te.sh test9.sh Ubuntu1204S Erver.img Ubuntu1204server.xml
Ubuntuguest.xml ubuntu-server.img win7.img

With the anti-quote, the shell executes LS as a command and returns the result.

Three types of quotes in the Linux 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.