The use of single quotes (') and double quotes (") in shell scripts distinguishes _linux shell

Source: Internet
Author: User

When you write a shell script on a Linux operating system, we use the $ symbol in front of the variable to get the value of the variable, usually in the script using the "$param" in a double quote format, but there are also the use of the ' $param ' with the quoted use of the scene, first of all, you see an example:

Copy Code code as follows:

[Root@linux ~]# Name=tektea
[Root@linux ~]# Echo $name
Tektea
[Root@linux ~]# sayhello= "Hello $name"
[Root@linux ~]# Echo $sayhello
Hello Tektea
[Root@linux ~]# sayhello= ' Hello $name '
[Root@linux ~]# Echo $sayhello
Hello $name

Did you find it? That's right! When using single quotes, that $name will lose the original variable content, only for the display of generic characters! There must be special care!

So the biggest difference between single and double quotes is that double quotes can still hold the contents of a variable, but single quotes can only be generic characters without special symbols, and we can also understand here: ' $sayhello ' and ' \ $sayhello ' are the same.

In the case of shell script development, single quotes (') and double quotes (") For variables are applied, which, in my experience, is:

1. Use double quotes (") When you get the value of a variable, which is the basic usage.

2. If you want to write a new script in the script, and you need to include variables in the new script, you can choose to use single quotes ('), especially when generating a temporary expect script, which is often used in single quotes (').

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.