Linux Shell single and double quotation marks

Source: Internet
Author: User

  

Quotation marks are often used when writing shell scripts, and sometimes the difference between single and double quotes is always forgotten.

So just tidy up for the future when the brain is not good to come to review. First, what they have in common: it seems like only

One is that they can all be used to define a string, which is nothing to explain, what really needs to be remembered is their differences,

So after finishing, their differences mainly include:

1), the single quotation mark is a strong reference, it ignores all the characters caused by the special processing, the quoted character will be the original

The only point to be aware of is that it is not allowed to refer to itself;

2), double quotation marks are weak references, it will be some of the characters caused by special processing, mainly including the following situations:

The 1:$ variable name can take the value of the variable, for example:

  [Email protected] ~]# echo ' $PWD '
$PWD 

[Email protected] ~]# echo "$PWD"

/root

2: Anti-quotes and $ () characters that are caused by the command are replaced with the original characters after they are executed, such as:

  [[email protected] ~]# echo ' $ (echo Hello World) '
$ (echo Hello World)
[[email protected] ~]# echo "$ (echo Hello World)"
Hello World

[Email protected] ~]# echo "Echo Hello World"
' Echo Hello World '
[Email protected] ~]# echo "' Echo Hello World '"
Hello World

3: Must be escaped when the character ($ ' " \) needs to be used , that is, in front plus \;

[[email protected] ~]# echo ' $ ' "\ '
$ ` " \
[Email protected] ~]# echo "\$ \ \" \ \ "
$ ` " \

  Remark: Bash/bin/sh, Version: 4.2.46 (2016-06-21-14:21:46)

Linux Shell single and double quotation marks

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.